#include "includes_fw.h"
#include "lib_retina.h"

#include "mmpf_sensor.h"
#include "mmpf_system.h"
#include "mmpf_sif.h"
#include "mmpf_sf.h"

#include "mmp_reg_usb.h"

#include "mmpf_usbvend.h"
#include "mmpf_usbextrn.h"
#include "mmpf_usbdescr.h"
#include "mmpf_usbuvc.h"
#include "mmpf_usbcolor.h"
#include "mmpf_usbuvch264.h"
#include "mmpf_usbxu.h"
#include "mmpf_mp4venc.h" //for FPS_CTL
#include "mmpf_3gpmgr.h"
#include "mmps_3gprecd.h"

#include "pcam_dfu.h"
#include "pcam_usb.h"
#include "pcam_msg.h"
#include "text_ctl.h"

#if CUSTOMER == ASU
#include "mmpf_vif.h"
#endif
#if (CUSTOMER == PNS) && defined(BUILD_LIB)
#include "framework.h"
#endif
#if SUPPORT_OSD_FUNC
#include "pCam_osd_api.h"
#endif

#if (SUPPORT_H264MV_MD)
#include "motion_dtc.h"
#endif

MMP_UBYTE gbUVCDSCCommand = 0;
MMP_UBYTE gbUVCPara[8];

extern MMP_UBYTE UsbRequestPayload_bmRequestType;
extern MMP_UBYTE UsbRequestPayload_bRequest;
extern MMP_USHORT UsbRequestPayload_wValue;
extern MMP_USHORT UsbRequestPayload_wIndex;
extern MMP_USHORT UsbRequestPayload_wLength;

extern MMP_UBYTE  USBOutData;
extern UVCX_VIDEO_CONFIG video_probe;

extern MMPF_SENSOR_FUNCTION *gsSensorFunction;

extern MMP_UBYTE   gbBandFilter;
extern MMP_RELEASE_VERSION gbFwVersion;
extern MMP_SYSTEM_BUILD_VERSION mmpf_buildVersion;
extern MMP_ULONG glCustomTargetSizePerFrame;
extern MMP_BOOL     m_bVidRecdPreviewStatus;

extern MMP_UBYTE gsUSBXU_I2C_ID;

extern MMP_ULONG    glPccamResolution;
extern MMP_USHORT      gsVideoEncodeFPS;

extern H264_FORMAT_TYPE gbCurH264Type;
extern MMP_UBYTE  gbCurFormatIndex, gbCurFrameIndex;
extern MMP_UBYTE gbSkypeMode;
extern MMP_UBYTE gbSkypeEncRes;
extern MMP_UBYTE gbSwitchSensor;
extern MMP_UBYTE gbCurrentSensor;

#if SKYPE_UVC_H264
extern MMP_USHORT              gsUVCXVersion;
extern MMP_ULONG               glUVCXFrameRate;
extern UVCX_VIDEO_CONFIG video_probe;
extern UVCX_PictureTypeCtl pict_type;
extern UVCX_FrameRateConfig fr;
//extern UVCX_BitRateLayers bitrate;

extern UVCX_VIDEO_CONFIG gsUVCXVideoConfigProbe_Def;
extern UVCX_VIDEO_CONFIG gsUVCXVideoConfigProbe_Cur;
extern UVCX_VIDEO_CONFIG gsUVCXVideoConfigProbe_Max;
extern UVCX_VIDEO_CONFIG gsUVCXVideoConfigProbe_Min;
extern UVCX_PictureTypeCtl  gsUVCXPictureTypeControl;
extern UVCX_FrameRateConfig  gsUVCXFrameRateConfig;
extern UVCX_BitRateLayers  gsUVCXBitRateLayers;
extern UVCX_AdvConfig        gsUVCXAdvConfig;
extern UVCX_QPStepSize         gsUVCXQPStepSize;

extern VC_CMD_CFG UVCX_VIDEO_CONFIG_PROBE_CFG;
extern VC_CMD_CFG UVCX_VIDEO_CONFIG_COMMIT_CFG;
extern VC_CMD_CFG UVCX_CONTROL_MODE_CFG;
extern VC_CMD_CFG UVCX_PICTURE_TYPE_CONTROL_CFG;
extern VC_CMD_CFG UVCX_VERSION_CFG;
extern VC_CMD_CFG UVCX_FRAMERATE_CONFIG_CFG;
extern VC_CMD_CFG UVCX_VIDEO_ADVANCE_CONFIG_CFG;
extern VC_CMD_CFG UVCX_BITRATE_CFG;
extern VC_CMD_CFG UVCX_QP_STEPS_SIZE_CFG;
extern VC_CMD_CFG UVCX_ENCODER_RESET_CFG;

extern UVCX_VIDEO_CONFIG gsCurH264Config;
extern UVCX_VIDEO_CONFIG gsCurPreviewConfig;
#endif

extern MMP_BOOL    gbAutoFocus;
extern MMP_UBYTE   gbBandFilter;
extern MMP_UBYTE   gbTemperInfo;
extern MMP_UBYTE   gbEVInfo;
extern MMP_UBYTE   gbGainInfo;
extern MMP_UBYTE   gbAWB;
extern MMP_UBYTE   gblastAWB;
extern MMP_UBYTE   gbAE;
extern MMP_UBYTE   gblastAE;
extern MMP_UBYTE   gbUpdAE;
extern MMP_UBYTE   gbUpdAWB;
extern MMP_UBYTE   gbUpdAG;
extern MMP_UBYTE   gbTriOP;

extern MMP_USHORT  gsAFocus;
extern MMP_USHORT  gsZoom;
extern MMP_USHORT  gsBacklight;
extern MMP_USHORT  gsTemper;
extern MMP_USHORT  gsSaturation;
extern MMP_USHORT  gsContrast;
extern MMP_USHORT  gsBrightness;
extern MMP_ULONG   gsEV;
extern MMP_SHORT   gsHue;
extern MMP_SHORT   gsGamma;
extern MMP_SHORT   gsSharpness;
extern MMP_USHORT  gsGain;

extern MMP_LONG    glPan,glTilt;

extern MMP_UBYTE gbLenShadingStatus;
extern MMP_UBYTE gbDeNoiseStatus;
extern MMP_UBYTE gbGammaStatus;
extern MMP_UBYTE gbColorMatrixStatus;
extern MMP_UBYTE gbEdgeEnhancementStatus;
extern MMP_UBYTE gbAEStatus;
extern MMP_UBYTE gbAWBStatus;
extern MMP_UBYTE gbAudioMode;

#if CUSTOMER == ASU
void xu_asu_config_tae(void);
void xu_asu_config_taf(void);
void xu_asu_config_twindow(void);
#endif

#if SUPPORT_OSD_FUNC
extern MMP_BYTE strTimeDate[];
extern MMP_BYTE strCustomerData[];
extern MMP_UBYTE gbOSDForeColorY;
extern MMP_USHORT gsOSDForeColorUV;
extern MMP_UBYTE gbOSDBackColorY;
extern MMP_USHORT gsOSDBackColorUV;
#if (MOVE_OSD_USING_DMA)
extern MMP_ULONG glOSDBufferYAddr[], glOSDBufferUVAddr[];
extern MMP_ULONG glOSDBufferYSize[], glOSDBufferUVSize[];
#endif
MMP_BOOL bEnableSetData32Transfer = MMP_FALSE; //enable to receive data from EU1_SET_DATA_32 
#endif

#if (SECS_VER > 0)

#define SKYPE_MAX_W         (1920)
#define SKYPE_MIN_W         (160)
#define SKYPE_MAX_H         (1080)
#define SKYPE_MIN_H         (90)


SKYPE_UVC_PROBE   SkypeUVCProbeIn, SkypeUVCProbe, SkypeUVCCommit;

SKYPE_UVC_PROBE gsSkypeStreamFormat_Probe_Def[2] =
{
{
SKYPE_FORMAT_H264,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
640, // wWidth
480, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
},
{
SKYPE_FORMAT_YUY2,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
160, // wWidth
120, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
}
} ;

SKYPE_UVC_PROBE gsSkypeStreamFormat_Probe_Cur[2] =
{
{
SKYPE_FORMAT_H264,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
640, // wWidth
480, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
},
{
SKYPE_FORMAT_YUY2,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
160, // wWidth
120, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
}
} ;

SKYPE_UVC_PROBE gsSkypeStreamFormat_Probe_Min[2] =
{
{
SKYPE_FORMAT_YUY2,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
SKYPE_MIN_W, // wWidth
SKYPE_MIN_H, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
25000, // dwBitrate in bits per second
},
{
SKYPE_FORMAT_YUY2,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
SKYPE_MIN_W, // wWidth
SKYPE_MIN_H, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
25000, // dwBitrate in bits per second
}
} ;

SKYPE_UVC_PROBE gsSkypeStreamFormat_Probe_Max[2] =
{
{
SKYPE_FORMAT_H264,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
SKYPE_MAX_W, // wWidth
SKYPE_MAX_H, // wHeight
SKYPE_FR_INTERVAL(15), // FrameInterval in 100ns unit
5000000, // dwBitrate in bits per second
},
{
SKYPE_FORMAT_H264,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
640, // wWidth
480, // wHeight
SKYPE_FR_INTERVAL(15), // FrameInterval in 100ns unit
1000000, // dwBitrate in bits per second
}
} ;

SKYPE_UVC_PROBE gsSkypeStreamFormat_Commit_Def[2] =
{
{
SKYPE_FORMAT_H264,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
640, // wWidth
480, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
},
{
SKYPE_FORMAT_YUY2,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
160, // wWidth
120, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
}
} ;

SKYPE_UVC_PROBE gsSkypeStreamFormat_Commit_Cur[2] =
{
#if 1
{
SKYPE_FORMAT_YUY2,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
640, // wWidth
480, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
},
{
SKYPE_FORMAT_YUY2,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
160, // wWidth
120, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
}
#else
{
3,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
1920, // wWidth
1080, // wHeight
330000, // FrameInterval in 100ns unit
4000000, // dwBitrate in bits per second
},
{
0,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
320, // wWidth
240, // wHeight
330000, // FrameInterval in 100ns unit
500000, // dwBitrate in bits per second
}

#endif
} ;

SKYPE_UVC_PROBE gsSkypeStreamFormat_Commit_Min[2] =
{
{
0,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
SKYPE_MIN_W, // wWidth
SKYPE_MIN_H, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
25000, // dwBitrate in bits per second
},
{
0,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
SKYPE_MIN_W, // wWidth
SKYPE_MIN_H, // wHeight
SKYPE_FR_INTERVAL(30), // FrameInterval in 100ns unit
25000, // dwBitrate in bits per second
}
} ;

SKYPE_UVC_PROBE gsSkypeStreamFormat_Commit_Max[2] =
{
{
3,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
SKYPE_MAX_W, // wWidth
SKYPE_MAX_H, // wHeight
SKYPE_FR_INTERVAL(15), // FrameInterval in 100ns unit
2500000, // dwBitrate in bits per second
},
{
3,  // 0: YUY2, 1: NV12, 2: MJPEG, 3: H.264
SKYPE_MAX_W, // wWidth
SKYPE_MAX_H, // wHeight
SKYPE_FR_INTERVAL(15), // FrameInterval in 100ns unit
2500000, // dwBitrate in bits per second
}
} ;

#define EU0_CMD01_SKYPE_UVCVER      (1)
#define     EU0_CMD01_LEN                  (0x0001)
#define     EU0_CMD01_MIN                  (0x21)
#define     EU0_CMD01_MAX                  (0x21)
#define     EU0_CMD01_DEF                  (0x21)
#define     EU0_CMD01_RES                  (0x01)

#define EU0_CMD02_SKYPE_LASTERR     (2)
#define     EU0_CMD02_LEN                  (0x0001)
#define     EU0_CMD02_MIN                  (0x00)
#define     EU0_CMD02_MAX                  (0x03)
#define     EU0_CMD02_DEF                  (0x00)
#define     EU0_CMD02_RES                  (0x0001)

#define EU0_CMD03_SKYPE_FWDAYS      (3)
#define     EU0_CMD03_LEN                  (0x0002)
#define     EU0_CMD03_MIN                  (0x0F00)
#define     EU0_CMD03_MAX                  (0xFFFF)
#define     EU0_CMD03_DEF                  (0x0F00)
#define     EU0_CMD03_RES                  (0x0001)

#define EU0_CMD04_STREAM_ID         (4)
#define     EU0_CMD04_LEN                  (0x0001)
#define     EU0_CMD04_MIN                  (0x00)
#define     EU0_CMD04_MAX                  (0x01)
#define     EU0_CMD04_DEF                  (0x00)
#define     EU0_CMD04_RES                  (0x01)

#define EU0_CMD05_ENDPOINT_SETTING  (5)
#define     EU0_CMD05_LEN                  (0x0001)
#define     EU0_CMD05_MIN                  (0x00)
#define     EU0_CMD05_MAX                  (0x00)
#define     EU0_CMD05_DEF                  (0x00)
#define     EU0_CMD05_RES                  (0x00)


#define EU0_CMD08_FORMAT_PROBE      (8)
#define     EU0_CMD08_LEN                  (0x000D)


#define EU0_CMD09_FORMAT_COMMIT     (9)
#define     EU0_CMD09_LEN                  (0x000D)


#define EU0_CMD10_STREAM_FORMAT_PROBE_TYPE              (10)
#define     EU0_CMD10_LEN                  (0x0001)
#define     EU0_CMD10_MIN                  (0x00)
#define     EU0_CMD10_MAX                  (0x03)
#define     EU0_CMD10_DEF                  (0x03)
#define     EU0_CMD10_RES                  (0x01)

#define EU0_CMD11_STREAM_FORMAT_PROBE_WIDTH             (11)
#define     EU0_CMD11_LEN                  (0x0002)
#define     EU0_CMD11_MIN                  (160)
#define     EU0_CMD11_MAX                  (1920)
#define     EU0_CMD11_DEF                  (1280)
#define     EU0_CMD11_RES                  (16)


#define EU0_CMD12_STREAM_FORMAT_PROBE_HEIGHT            (12)
#define     EU0_CMD12_LEN                  (0x0002)
#define     EU0_CMD12_MIN                  (120)
#define     EU0_CMD12_MAX                  (1080)
#define     EU0_CMD12_DEF                  (720)
#define     EU0_CMD12_RES                  (16)

#define EU0_CMD13_STREAM_FORMAT_PROBE_FRAME_INTERVAL    (13)
#define     EU0_CMD13_LEN                  (0x0004)
#define     EU0_CMD13_MIN                  (330000)
#define     EU0_CMD13_MAX                  (2000000)
#define     EU0_CMD13_DEF                  (330000)
#define     EU0_CMD13_RES                  (10000)


#define EU0_CMD14_STREAM_FORMAT_PROBE_FRAME_BITRATE     (14)
#define     EU0_CMD14_LEN                  (0x0004)
#define     EU0_CMD14_MIN                  (25000)
#define     EU0_CMD14_MAX                  (5000000)
#define     EU0_CMD14_DEF                  (3000000)
#define     EU0_CMD14_RES                  (10000)

#define EU0_CMD24_BITRATE           (24)
#define     EU0_CMD24_LEN                  (0x0004)


#define EU0_CMD25_FRAME_INTERVAL    (25)
#define     EU0_CMD25_LEN                  (0x0004)


#define EU0_CMD26_GENERATE_KEY_FRAME  (26)
#define     EU0_CMD26_LEN                  (0x0001)


MMP_ULONG glSkypeFrameInterval[2] = {SKYPE_FR_INTERVAL(30), SKYPE_FR_INTERVAL(30)};
MMP_ULONG glSkypeBitRate[2] = {500000, 500000};
MMP_UBYTE gbSkypeEnforceKey[2] = {0x00, 0x00};
MMP_USHORT gsSkypeFWDays = 0x0E5A;
MMP_UBYTE gbSkypeUVCVersion = 0x21;  // valid value = 0x12(version 1.2)
MMP_UBYTE gbSkypeInterfaceType = 0;  // 0: single endpoint, 1: dual endpoint, main first and preview second, 2:
MMP_UBYTE gbCurStreamID = 0;
MMP_UBYTE gbSkypeLastError = 0;
MMP_UBYTE gbProbeStreamFormatType = SKYPE_FORMAT_H264;
MMP_USHORT gsProbeStreamFormatWidth = 0 ;
MMP_USHORT gsProbeStreamFormatHeigth = 0 ;
MMP_ULONG  glProbeStreamFormatFrameInterval = 0;
MMP_ULONG  glProbeStreamFormatBitRate = 0;

void usb_vc_set_skype_uvc_probe(SKYPE_UVC_PROBE *pSPIN)
{
    gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].bStreamType = pSPIN->bStreamType;
    gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].wWidth = pSPIN->wWidth;
    gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].wHeight = pSPIN->wHeight;
    gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].dwFrameInterval = pSPIN->dwFrameInterval;
    gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].dwBitrate = pSPIN->dwBitrate;
}

void usb_vc_set_skype_uvc_commit(SKYPE_UVC_PROBE *pSPIN)
{
    gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].bStreamType = pSPIN->bStreamType;
    gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].wWidth = pSPIN->wWidth;
    gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].wHeight = pSPIN->wHeight;
    gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].dwFrameInterval = pSPIN->dwFrameInterval;
    gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].dwBitrate = pSPIN->dwBitrate;
}

// Version Control
VC_CMD_CFG VC_XU_SKYPE_CMD01_UVCVER_CFG = {
(CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT),
EU0_CMD01_LEN,
(CMD_VALUE) EU0_CMD01_RES,(CMD_VALUE) EU0_CMD01_DEF,(CMD_VALUE) EU0_CMD01_MIN,(CMD_VALUE) EU0_CMD01_MAX,
(CMD_VALUE) EU0_CMD01_DEF
} ;

// Last Error
VC_CMD_CFG VC_XU_SKYPE_CMD02_LASTERR_CFG = {
(CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT),
EU0_CMD02_LEN,
(CMD_VALUE) EU0_CMD02_RES,(CMD_VALUE) EU0_CMD02_DEF,(CMD_VALUE) EU0_CMD02_MIN,(CMD_VALUE) EU0_CMD02_MAX,
(CMD_VALUE) EU0_CMD02_DEF
} ;

// Firmware Days Control
VC_CMD_CFG VC_XU_SKYPE_CMD03_FWDAYS_CFG = {
(CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT),
EU0_CMD03_LEN,
(CMD_VALUE) EU0_CMD03_RES,(CMD_VALUE) EU0_CMD03_DEF,(CMD_VALUE) EU0_CMD03_MIN,(CMD_VALUE) EU0_CMD03_MAX,
(CMD_VALUE) EU0_CMD03_DEF
} ;

// Stream ID Control
VC_CMD_CFG VC_XU_SKYPE_CMD04_STREAMID_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD04_LEN,
(CMD_VALUE) EU0_CMD04_RES,(CMD_VALUE) EU0_CMD04_DEF,(CMD_VALUE) EU0_CMD04_MIN,(CMD_VALUE) EU0_CMD04_MAX,
(CMD_VALUE) EU0_CMD04_DEF
} ;

// EndpointSetting Control
VC_CMD_CFG VC_XU_SKYPE_CMD05_ENDPOINTINFO_CFG = {
(CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT),
EU0_CMD05_LEN,
(CMD_VALUE) EU0_CMD05_RES,(CMD_VALUE) EU0_CMD05_DEF,(CMD_VALUE) EU0_CMD05_MIN,(CMD_VALUE) EU0_CMD05_MAX,
(CMD_VALUE) EU0_CMD05_DEF
} ;

// Stream Format Probe Control
VC_CMD_CFG VC_XU_SKYPE_CMD08_FORMATPROBE_0_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD08_LEN,
(CMD_VALUE) 0,
(CMD_VALUE) & gsSkypeStreamFormat_Probe_Def[0],
(CMD_VALUE) & gsSkypeStreamFormat_Probe_Min[0],
(CMD_VALUE) & gsSkypeStreamFormat_Probe_Max[0],
(CMD_VALUE) & gsSkypeStreamFormat_Probe_Cur[0]
} ;

VC_CMD_CFG VC_XU_SKYPE_CMD08_FORMATPROBE_1_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD08_LEN,
(CMD_VALUE) 0,
(CMD_VALUE) & gsSkypeStreamFormat_Probe_Def[1],
(CMD_VALUE) & gsSkypeStreamFormat_Probe_Min[1],
(CMD_VALUE) & gsSkypeStreamFormat_Probe_Max[1],
(CMD_VALUE) & gsSkypeStreamFormat_Probe_Cur[1]
} ;


// Stream Format Commit Control
VC_CMD_CFG VC_XU_SKYPE_CMD09_FORMATCOMMIT_0_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD09_LEN,
(CMD_VALUE) 0,
(CMD_VALUE) & gsSkypeStreamFormat_Commit_Def[0],
(CMD_VALUE) & gsSkypeStreamFormat_Commit_Min[0],
(CMD_VALUE) & gsSkypeStreamFormat_Commit_Max[0],
(CMD_VALUE) & gsSkypeStreamFormat_Commit_Cur[0]
} ;

VC_CMD_CFG VC_XU_SKYPE_CMD09_FORMATCOMMIT_1_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD09_LEN,
(CMD_VALUE) 0,
(CMD_VALUE) & gsSkypeStreamFormat_Commit_Def[1],
(CMD_VALUE) & gsSkypeStreamFormat_Commit_Min[1],
(CMD_VALUE) & gsSkypeStreamFormat_Commit_Max[1],
(CMD_VALUE) & gsSkypeStreamFormat_Commit_Cur[1]
} ;


VC_CMD_CFG VC_XU_SKYPE_CMD10_PROBE_TYPE_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD10_LEN,
(CMD_VALUE) EU0_CMD10_RES,(CMD_VALUE) SKYPE_FORMAT_H264,(CMD_VALUE) SKYPE_FORMAT_YUY2,(CMD_VALUE) SKYPE_FORMAT_H264,
(CMD_VALUE) SKYPE_FORMAT_H264
} ;


VC_CMD_CFG VC_XU_SKYPE_CMD11_PROBE_WIDTH_CFG = {
(CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT),
EU0_CMD11_LEN,
(CMD_VALUE) EU0_CMD11_RES,(CMD_VALUE) EU0_CMD11_DEF,(CMD_VALUE) EU0_CMD11_MIN,(CMD_VALUE) EU0_CMD11_MAX,
(CMD_VALUE) EU0_CMD11_DEF
} ;


VC_CMD_CFG VC_XU_SKYPE_CMD12_PROBE_HEIGHT_CFG = {
(CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT),
EU0_CMD12_LEN,
(CMD_VALUE) EU0_CMD12_RES,(CMD_VALUE) EU0_CMD12_DEF,(CMD_VALUE) EU0_CMD12_MIN,(CMD_VALUE) EU0_CMD12_MAX,
(CMD_VALUE) EU0_CMD12_DEF
} ;

VC_CMD_CFG VC_XU_SKYPE_CMD13_PROBE_FPS_CFG = {
(CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT),
EU0_CMD13_LEN,
(CMD_VALUE) EU0_CMD13_RES,(CMD_VALUE) SKYPE_FR_INTERVAL(30),(CMD_VALUE) SKYPE_FR_INTERVAL(30),
(CMD_VALUE) SKYPE_FR_INTERVAL(15),(CMD_VALUE) SKYPE_FR_INTERVAL(30)
} ;


VC_CMD_CFG VC_XU_SKYPE_CMD14_PROBE_BITRATE_CFG = {
(CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT),
EU0_CMD14_LEN,
(CMD_VALUE) EU0_CMD14_RES,(CMD_VALUE) EU0_CMD14_DEF,(CMD_VALUE) EU0_CMD14_MIN,(CMD_VALUE) EU0_CMD14_MAX,
(CMD_VALUE) EU0_CMD14_DEF
} ;



// Dynamic Bitrate Control
VC_CMD_CFG VC_XU_SKYPE_CMD24_BITRATE_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD24_LEN,
(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0
} ;

// Dynamic Frame Interval Control
VC_CMD_CFG VC_XU_SKYPE_CMD25_FRAMEINTERVAL_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD25_LEN,
(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0
} ;

// Generate Key Frame Control
VC_CMD_CFG VC_XU_SKYPE_CMD26_ENFORCEKEY_CFG = {
(CAP_GET_INFO_CMD | CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_LEN_CMD | CAP_GET_RES_CMD | CAP_GET_DEF_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU0_CMD26_LEN,
(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0
} ;

void usb_vc_eu0_cs(MMP_UBYTE req)
{
    MMP_UBYTE cs;
    //    volatile MMP_UBYTE *USB_REG_BASE_B = (volatile MMP_UBYTE *) USB_REG_BASE_ADDR;

    cs = (UsbRequestPayload_wValue >> 8);

#if 0
    dbg_printf(0, "eu0_cs(cs=%x)\r\n",cs);
#endif

    UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);

    switch(cs){
    case EU0_CMD01_SKYPE_UVCVER:
        //RTNA_DBG_Str(0,"EU0_CMDe_SKYPE_UVCVER\r\n");
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD01_UVCVER_CFG, (CMD_VALUE) gbSkypeUVCVersion);
        break;

    case EU0_CMD02_SKYPE_LASTERR:
        //RTNA_DBG_Str(0,"EU0_CMD0_SKYPE_LASTERR\r\n");
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD02_LASTERR_CFG, (CMD_VALUE) gbSkypeLastError);
        break;

    case EU0_CMD03_SKYPE_FWDAYS:
        //RTNA_DBG_Str(0,"EU0_CMDa_SKYPE_FWDAYS\r\n");
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD03_FWDAYS_CFG, (CMD_VALUE) gsSkypeFWDays);
        break;

    case EU0_CMD04_STREAM_ID:
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD04_STREAMID_CFG, (CMD_VALUE) gbCurStreamID);
        //RTNA_DBG_Str0("EU0_CMD04_STREAM_ID: [GET_CUR] \r\n");
        break;

    case EU0_CMD05_ENDPOINT_SETTING:
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD05_ENDPOINTINFO_CFG, (CMD_VALUE) gbSkypeInterfaceType);
        break;

    case EU0_CMD08_FORMAT_PROBE:
        if(gbCurStreamID == 0){
            usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD08_FORMATPROBE_0_CFG,
                           (CMD_VALUE) & gsSkypeStreamFormat_Probe_Cur[gbCurStreamID]);
            //RTNA_DBG_Str0("EU0_CMD08_FORMAT_PROBE: [GET_CUR] 0 \r\n");
        }
        else{
            usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD08_FORMATPROBE_1_CFG,
                           (CMD_VALUE) & gsSkypeStreamFormat_Probe_Cur[gbCurStreamID]);
            //RTNA_DBG_Str0("EU0_CMD08_FORMAT_PROBE: [GET_CUR] 1 \r\n");
        }
        break;

    case EU0_CMD09_FORMAT_COMMIT:
        if(gbCurStreamID == 0){
            usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD09_FORMATCOMMIT_0_CFG,
                           (CMD_VALUE) & gsSkypeStreamFormat_Commit_Cur[gbCurStreamID]);
            //RTNA_DBG_Str0("EU0_CMD09_FORMAT_COMMIT: [GET_CUR] 0 \r\n");
        }
        else{
            usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD09_FORMATCOMMIT_1_CFG,
                           (CMD_VALUE) & gsSkypeStreamFormat_Commit_Cur[gbCurStreamID]);
            //RTNA_DBG_Str0("EU0_CMD09_FORMAT_COMMIT: [GET_CUR] 1 \r\n");
        }
        break;

    case EU0_CMD10_STREAM_FORMAT_PROBE_TYPE:
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD10_PROBE_TYPE_CFG, (CMD_VALUE) gbProbeStreamFormatType);
        break;
    case EU0_CMD11_STREAM_FORMAT_PROBE_WIDTH:
        if(gbProbeStreamFormatType == SKYPE_FORMAT_H264){
            VC_XU_SKYPE_CMD11_PROBE_WIDTH_CFG.dwMinVal = (CMD_VALUE) 160 ;
            VC_XU_SKYPE_CMD11_PROBE_WIDTH_CFG.dwMaxVal = (CMD_VALUE) 1280 ;
        }
        else{
            VC_XU_SKYPE_CMD11_PROBE_WIDTH_CFG.dwMinVal = (CMD_VALUE) 160 ;
            VC_XU_SKYPE_CMD11_PROBE_WIDTH_CFG.dwMaxVal = (CMD_VALUE) 320 ;
        }
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD11_PROBE_WIDTH_CFG, (CMD_VALUE) gsProbeStreamFormatWidth);
        break;
    case EU0_CMD12_STREAM_FORMAT_PROBE_HEIGHT:
        if(gbProbeStreamFormatType == SKYPE_FORMAT_H264){
            VC_XU_SKYPE_CMD12_PROBE_HEIGHT_CFG.dwMinVal = (CMD_VALUE) 90 ;
            VC_XU_SKYPE_CMD12_PROBE_HEIGHT_CFG.dwMaxVal = (CMD_VALUE) 720 ;
        }
        else{
            VC_XU_SKYPE_CMD12_PROBE_HEIGHT_CFG.dwMinVal = (CMD_VALUE) 90 ;
            VC_XU_SKYPE_CMD12_PROBE_HEIGHT_CFG.dwMaxVal = (CMD_VALUE) 180 ;
        }
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD12_PROBE_HEIGHT_CFG, (CMD_VALUE) gsProbeStreamFormatHeigth);
        break;


    case EU0_CMD13_STREAM_FORMAT_PROBE_FRAME_INTERVAL:
        if(gbProbeStreamFormatType == SKYPE_FORMAT_H264){
            VC_XU_SKYPE_CMD13_PROBE_FPS_CFG.dwMinVal = (CMD_VALUE) SKYPE_FR_INTERVAL(30) ;
            VC_XU_SKYPE_CMD13_PROBE_FPS_CFG.dwMaxVal = (CMD_VALUE) SKYPE_FR_INTERVAL(15) ;
        }
        else{
            VC_XU_SKYPE_CMD13_PROBE_FPS_CFG.dwMinVal = (CMD_VALUE) SKYPE_FR_INTERVAL(30) ;
            VC_XU_SKYPE_CMD13_PROBE_FPS_CFG.dwMaxVal = (CMD_VALUE) SKYPE_FR_INTERVAL(15) ;
        }
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD13_PROBE_FPS_CFG, (CMD_VALUE) glProbeStreamFormatFrameInterval);
        break;
    case EU0_CMD14_STREAM_FORMAT_PROBE_FRAME_BITRATE:
        if(gbProbeStreamFormatType == SKYPE_FORMAT_H264){
            VC_XU_SKYPE_CMD14_PROBE_BITRATE_CFG.dwMinVal = (CMD_VALUE) 25000 ;
            VC_XU_SKYPE_CMD14_PROBE_BITRATE_CFG.dwMaxVal = (CMD_VALUE) 5000000 ;
        }
        else{
            VC_XU_SKYPE_CMD14_PROBE_BITRATE_CFG.dwMinVal = (CMD_VALUE) (160 * 90 * 2 * 15) ;
            VC_XU_SKYPE_CMD14_PROBE_BITRATE_CFG.dwMaxVal = (CMD_VALUE) (320 * 180 * 2 * 30) ;
        }
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD14_PROBE_BITRATE_CFG, (CMD_VALUE) glProbeStreamFormatBitRate);
        break;

    case EU0_CMD24_BITRATE:
        //bit rate
        //RTNA_DBG_Str(0,"EU0_CMD3_SKYPE_BITRATE\r\n");
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD24_BITRATE_CFG, (CMD_VALUE) glSkypeBitRate[gbCurStreamID]);
        break;

    case EU0_CMD25_FRAME_INTERVAL:
        //frame rate
        //RTNA_DBG_Str(0,"EU0_CMD2_SKYPE_FRAMERATE\r\n");
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD25_FRAMEINTERVAL_CFG, (CMD_VALUE) glSkypeFrameInterval[gbCurStreamID]);
        break;

    case EU0_CMD26_GENERATE_KEY_FRAME:
        //force key frame
        //RTNA_DBG_Str(0,"EU0_CMD4_SKYPE_ENFORCEKEY\r\n");
        usb_vc_cmd_cfg(req, &VC_XU_SKYPE_CMD26_ENFORCEKEY_CFG, (CMD_VALUE) gbSkypeEnforceKey[gbCurStreamID]);
        break;

    default:
        usb_vc_stall(CONTROL_INVALID_CONTROL);
        break;
    }
}

void usb_vc_eu0_cs_out(void)
{
    //
    MMP_UBYTE cs,len, /*i, *ptr,*/ streamid, kf;
    MMP_UBYTE *tmpptrb;
    MMP_ULONG br, ft;
    MMP_BOOL IsPreviewEnable ;
    //volatile MMP_UBYTE *USB_REG_BASE_B = (volatile MMP_UBYTE *) USB_REG_BASE_ADDR;
    SKYPE_RES_TYPE_CFG *cur_res;

    cs = (UsbRequestPayload_wValue >> 8);
    len = UsbRequestPayload_wLength;

#if 0
    RTNA_DBG_Str(0, "usb_vc_eu0_cs_out()\r\n");
    RTNA_DBG_Str(0, "cs = ");
    RTNA_DBG_Byte(0, cs);
    RTNA_DBG_Str(0, " : len = ");
    RTNA_DBG_Byte(0, len);
    RTNA_DBG_Str(0, "\r\n");
#endif

    switch(cs){
    case EU0_CMD04_STREAM_ID:
        USBOutData = 0;
        USB_GET_FIFO_DATA(MMPF_USB_EP0, len, &streamid, EU0_CMD04_LEN);

        if(streamid > 1){
            gbSkypeLastError = SKYPE_INVALID_ARGUMENT;
            RTNA_DBG_Str(0, " ** EU0_CMD04_STREAM_ID error\r\n");
            goto cmd04_exit;
        }

        gbCurStreamID = streamid;
#if 0
RTNA_DBG_Str(0,"gbCurStreamID = ");
RTNA_DBG_Byte(0,gbCurStreamID);
RTNA_DBG_Str(0,"\r\n");
#endif
        gbSkypeLastError = SKYPE_NO_ERROR;

cmd04_exit:
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU0_CMD08_FORMAT_PROBE:
        USBOutData = 0;
        tmpptrb = (MMP_UBYTE *) &SkypeUVCProbeIn;
        USB_GET_FIFO_DATA(MMPF_USB_EP0, len, tmpptrb, EU0_CMD08_LEN);

        if(SkypeUVCProbeIn.bStreamType > SKYPE_FORMAT_H264){
            // 0:YUY2, 1:NV12, 2:MJPEG, 3:H.264
            // un-support
            //UsbWriteEp0CSR(SET_EP0_SENDSTALL | SET_EP0_SERVICED_RXPKTRDY);
            gbSkypeLastError = SKYPE_NOT_SUPPORTED;
            RTNA_DBG_Str(0, " ** EU0_CMD08_FORMAT_PROBE error\r\n");
            goto cmd08_exit;
        }
        /*
                if((SkypeUVCProbeIn.wWidth > 1280) || (SkypeUVCProbeIn.wHeight > 720) || (SkypeUVCProbeIn.wWidth < 160) || (SkypeUVCProbeIn.wHeight < 90)){
                    // un-support
                    //UsbWriteEp0CSR(SET_EP0_SENDSTALL | SET_EP0_SERVICED_RXPKTRDY);
                    gbSkypeLastError = SKYPE_NOT_SUPPORTED;
                    RTNA_DBG_Str(0, " ** EU0_CMD08_FORMAT_PROBE error\r\n");
                    goto cmd08_exit;
                }
        */
        if(gbCurStreamID > 1){
            gbSkypeLastError = SKYPE_NOT_SUPPORTED;
            RTNA_DBG_Str(0, " ** EU0_CMD08_FORMAT_PROBE error\r\n");
            goto cmd08_exit;
        }

        if((SkypeUVCProbeIn.bStreamType == SKYPE_FORMAT_NV12) || (SkypeUVCProbeIn.bStreamType == SKYPE_FORMAT_MJPEG)){
            // 0:YUY2, 1:NV12, 2:MJPEG, 3:H.264
            gbSkypeLastError = SKYPE_NOT_SUPPORTED;
            RTNA_DBG_Str(0, " ** EU0_CMD08_FORMAT_PROBE error\r\n");
            goto cmd08_exit;
        }

        if(SkypeUVCProbeIn.dwFrameInterval < 330000){
            //gbSkypeLastError = SKYPE_NOT_SUPPORTED;
            //RTNA_DBG_Str(0, " ** EU0_CMD08_FORMAT_PROBE error\r\n");
            //goto cmd08_exit;
            SkypeUVCProbeIn.dwFrameInterval = 330000;
        }
        else if(SkypeUVCProbeIn.dwFrameInterval > 2000000){
            SkypeUVCProbeIn.dwFrameInterval = 2000000;
        }

        if((SkypeUVCProbeIn.dwBitrate < 25000)){
            //gbSkypeLastError = SKYPE_NOT_SUPPORTED;
            //RTNA_DBG_Str(0, " ** EU0_CMD08_FORMAT_PROBE error\r\n");
            //goto cmd08_exit;
            SkypeUVCProbeIn.dwBitrate = 25000;
        }

        if(gbCurStreamID == 0){
            // main stream
            cur_res = SearchSkypeMainStreamRes(SkypeUVCProbeIn.wWidth, SkypeUVCProbeIn.wHeight);
        }
        else{
            cur_res = SearchSkypePreviewStreamRes(SkypeUVCProbeIn.wWidth, SkypeUVCProbeIn.wHeight);
        }

        SkypeUVCProbeIn.wWidth = cur_res->res_w;
        SkypeUVCProbeIn.wHeight = cur_res->res_h;

        usb_vc_set_skype_uvc_probe(&SkypeUVCProbeIn);

#if 1
        RTNA_DBG_Str0("EU0_CMD08_FORMAT_PROBE: [SET_CUR] \r\n");

        RTNA_DBG_Str(0, " ** gbCurStreamID = ");
        RTNA_DBG_Byte(0, gbCurStreamID);
        RTNA_DBG_Str(0, " **\r\n");
        RTNA_DBG_Str(0, " ** bStreamType = ");
        RTNA_DBG_Byte(0, gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].bStreamType);
        RTNA_DBG_Str(0, " **\r\n");
        RTNA_DBG_Str(0, " ** wWidth = ");
        MMPF_DBG_Int(gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].wWidth, -4);
        RTNA_DBG_Str(0, "  : ");
        RTNA_DBG_Str(0, " wHeight = ");
        MMPF_DBG_Int(gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].wHeight, -4);
        RTNA_DBG_Str(0, " **\r\n");
        RTNA_DBG_Str(0, " ** dwFrameInterval = ");
        MMPF_DBG_Int(gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].dwFrameInterval, -7);
        RTNA_DBG_Str(0, " **\r\n");
        RTNA_DBG_Str(0, " ** dwBitrate = ");
        MMPF_DBG_Int(gsSkypeStreamFormat_Probe_Cur[gbCurStreamID].dwBitrate, -8);
        RTNA_DBG_Str(0, " **\r\n");
#endif

        gbSkypeLastError = SKYPE_NO_ERROR;

cmd08_exit:
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU0_CMD09_FORMAT_COMMIT:
        USBOutData = 0;
        tmpptrb = (MMP_UBYTE *) &SkypeUVCProbeIn;
        USB_GET_FIFO_DATA(MMPF_USB_EP0, len, tmpptrb, EU0_CMD09_LEN);

        if(SkypeUVCProbeIn.bStreamType > SKYPE_FORMAT_H264){
            // 0:YUY2, 1:NV12, 2:MJPEG, 3:H.264
            // un-support
            //UsbWriteEp0CSR(SET_EP0_SENDSTALL | SET_EP0_SERVICED_RXPKTRDY);
            gbSkypeLastError = SKYPE_NOT_ALLOWED;
            RTNA_DBG_Str(0, " ** EU0_CMD09_FORMAT_COMMIT error\r\n");
            goto cmd09_exit;
        }
        /*
                if((SkypeUVCProbeIn.wWidth > 1280) || (SkypeUVCProbeIn.wHeight > 720) || (SkypeUVCProbeIn.wWidth < 160) || (SkypeUVCProbeIn.wHeight < 90)){
                    // un-support
                    //UsbWriteEp0CSR(SET_EP0_SENDSTALL | SET_EP0_SERVICED_RXPKTRDY);
                    gbSkypeLastError = SKYPE_NOT_ALLOWED;
                    RTNA_DBG_Str(0, " ** EU0_CMD09_FORMAT_COMMIT error\r\n");
                    goto cmd09_exit;
                }
        */
        if(gbCurStreamID > 1){
            gbSkypeLastError = SKYPE_NOT_ALLOWED;
            RTNA_DBG_Str(0, " ** EU0_CMD09_FORMAT_COMMIT error\r\n");
            goto cmd09_exit;
        }

        if((SkypeUVCProbeIn.bStreamType == SKYPE_FORMAT_NV12) || (SkypeUVCProbeIn.bStreamType == SKYPE_FORMAT_MJPEG)){
            // 0:YUY2, 1:NV12, 2:MJPEG, 3:H.264
            gbSkypeLastError = SKYPE_NOT_ALLOWED;
            RTNA_DBG_Str(0, " ** EU0_CMD09_FORMAT_COMMIT error\r\n");
            goto cmd09_exit;
        }

        if(SkypeUVCProbeIn.dwFrameInterval < 330000){
            //gbSkypeLastError = SKYPE_NOT_SUPPORTED;
            //RTNA_DBG_Str(0, " ** EU0_CMD08_FORMAT_PROBE error\r\n");
            //goto cmd08_exit;
            SkypeUVCProbeIn.dwFrameInterval = 330000;
        }
        else if(SkypeUVCProbeIn.dwFrameInterval > 2000000){
            SkypeUVCProbeIn.dwFrameInterval = 2000000;
        }

        if((SkypeUVCProbeIn.dwBitrate < 25000)){
            //gbSkypeLastError = SKYPE_NOT_SUPPORTED;
            //RTNA_DBG_Str(0, " ** EU0_CMD08_FORMAT_PROBE error\r\n");
            //goto cmd08_exit;
            SkypeUVCProbeIn.dwBitrate = 25000;
        }

        usb_vc_set_skype_uvc_commit(&SkypeUVCProbeIn);

#if 1
        RTNA_DBG_Str0("EU0_CMD09_FORMAT_COMMIT: [SET_CUR] \r\n");

        RTNA_DBG_Str(0, " ** gbCurStreamID = ");
        RTNA_DBG_Byte(0, gbCurStreamID);
        RTNA_DBG_Str(0, " **\r\n");
        RTNA_DBG_Str(0, " ** bStreamType = ");
        RTNA_DBG_Byte(0, gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].bStreamType);
        RTNA_DBG_Str(0, " **\r\n");
        RTNA_DBG_Str(0, " ** wWidth = ");
        MMPF_DBG_Int(gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].wWidth, -4);
        RTNA_DBG_Str(0, "  : ");
        RTNA_DBG_Str(0, " wHeight = ");
        MMPF_DBG_Int(gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].wHeight, -4);
        RTNA_DBG_Str(0, " **\r\n");
        RTNA_DBG_Str(0, " ** dwFrameInterval = ");
        MMPF_DBG_Int(gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].dwFrameInterval, -7);
        RTNA_DBG_Str(0, " **\r\n");
        RTNA_DBG_Str(0, " ** dwBitrate = ");
        MMPF_DBG_Int(gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].dwBitrate, -8);
        RTNA_DBG_Str(0, " **\r\n");
#endif

        gbSkypeLastError = SKYPE_NO_ERROR;

cmd09_exit:
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU0_CMD10_STREAM_FORMAT_PROBE_TYPE:
        USBOutData = 0;
        USB_GET_FIFO_DATA(MMPF_USB_EP0, len, &gbProbeStreamFormatType, EU0_CMD10_LEN);
        gbSkypeLastError = SKYPE_NO_ERROR;
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();

        break;

    case EU0_CMD24_BITRATE:
        USBOutData = 0;
        USB_GET_FIFO_DATA(MMPF_USB_EP0, len, (MMP_UBYTE *) &br, EU0_CMD24_LEN);

        if((br < 25000)){
            dbg_printf(3, "** br = %d\r\n", br);
            //gbSkypeLastError = SKYPE_NOT_SUPPORTED;
            RTNA_DBG_Str(0, " ** EU0_CMD24_BITRATE error\r\n");
            //goto cmd24_exit;
            br = 25000;
        }

        glSkypeBitRate[gbCurStreamID] = br;

        /*
                if(gsSkypeBitRate >= 3000)
                    gsSkypeBitRate = 3000;
                else if(gsSkypeBitRate <= 25)
                    gsSkypeBitRate = 25;
        */
#if (FPS_CTL == 1)   // bit rate control API test

        MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
        if(IsPreviewEnable){
            RTNA_DBG_Str(0, "  ** bitrate = ");
            MMPF_DBG_Int(glSkypeBitRate[gbCurStreamID], -8);
            //RTNA_DBG_Str(0, "  in/out fps ");
            //MMPF_DBG_Int(MMPF_VIDENC_GetInputFPS(0), -2);
            //MMPF_DBG_Int(MMPF_VIDENC_GetOutputFPS(0), -2);
            RTNA_DBG_Str(0, "\r\n");
            gsUVCXBitRateLayers.wLayerID = 0;
            gsUVCXBitRateLayers.dwPeakBitrate = glSkypeBitRate[gbCurStreamID] ;
            gsUVCXBitRateLayers.dwAverageBitrate = glSkypeBitRate[gbCurStreamID] ;
            UVCX_SetH264BitRate(gbCurStreamID, &gsUVCXBitRateLayers);
        }
        else{
            RTNA_DBG_Str(0, "  ** gsSkypeBitRate = ");
            MMPF_DBG_Int(glSkypeBitRate[gbCurStreamID], -8);
            RTNA_DBG_Str(0, "\r\n");

            if((MMP_LONG) glSkypeBitRate[gbCurStreamID] > 0)
                gsCurH264Config.dwBitRate = glSkypeBitRate[gbCurStreamID];
            //            gbVideoEncQualityCustom = MMP_TRUE;
            //            glCustomTargetSizePerFrame = (glSkypeBitRate[gbCurStreamID])/(8 * gsVideoEncodeFPS);
            //            gbCustomQp = 45;
        }

#endif

        gbSkypeLastError = SKYPE_NO_ERROR;

        //cmd24_exit:

        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;


    case EU0_CMD25_FRAME_INTERVAL:
        USBOutData = 0;
        USB_GET_FIFO_DATA(MMPF_USB_EP0, len, (MMP_UBYTE *) &ft, EU0_CMD25_LEN);

        if((ft < 330000) || (ft > 2000000)){
            gbSkypeLastError = SKYPE_NOT_ALLOWED;
            RTNA_DBG_Str(0, " ** EU0_CMD25_FRAME_INTERVAL error\r\n");
        }
        else{
            glSkypeFrameInterval[gbCurStreamID] = ft;

            //set encoder fps
#if (FPS_CTL == 1)
             {
                MMP_BOOL IsPreviewEnable;
                MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
                if(IsPreviewEnable){
                    UVCX_SetH264FrameRate(gbCurStreamID, glSkypeFrameInterval[gbCurStreamID]);
                }
                else{
                    gsCurH264Config.dwFrameInterval = glSkypeFrameInterval[gbCurStreamID] ;
                }
            }
#endif

            //RTNA_DBG_Str(0,"glSkypeFrameInterval = ");
            //MMPF_DBG_Int(glSkypeFrameInterval[gbCurStreamID], -7);
            //RTNA_DBG_Str(0,"\r\n");

            gbSkypeLastError = SKYPE_NO_ERROR;
        }

        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU0_CMD26_GENERATE_KEY_FRAME:
        USBOutData = 0;
        USB_GET_FIFO_DATA(MMPF_USB_EP0, len, (MMP_UBYTE *) &kf, EU0_CMD26_LEN);

        if(kf != 1){
            gbSkypeLastError = SKYPE_INVALID_ARGUMENT;
            RTNA_DBG_Str(0, " ** EU0_CMD26_GENERATE_KEY_FRAME error\r\n");
        }
        else{
            //        if(gsSkypeStreamFormat_Commit_Cur[gbCurStreamID].bStreamType != SKYPE_FORMAT_H264){
            //            gbSkypeLastError = SKYPE_NOT_ALLOWED;
            //            RTNA_DBG_Str(0, " ** EU0_CMD26_GENERATE_KEY_FRAME error\r\n");
            //            goto cmd26_exit;
            //        }

            gbSkypeEnforceKey[gbCurStreamID] = kf;

            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if(IsPreviewEnable){
                USB_ForceH264IDRFrame();  //Set IDR frame
            }

            RTNA_DBG_Str(0, "gbSkypeEnforcrKey = ");
            RTNA_DBG_Byte(0, gbSkypeEnforceKey[gbCurStreamID]);
            RTNA_DBG_Str(0, "\r\n");

            gbSkypeLastError = SKYPE_NO_ERROR;
        }

        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case XU_CONTROL_UNDEFINED:
    default:
        // impossible flow
        break;
    }
}
#endif




#define EU1_SET_ISP             (0x1)   //command number
#define EU1_SET_ISP_LEN         (0x08)
#define EU1_SET_ISP_MIN         (0x0)
#define EU1_SET_ISP_MAX         (0xFFFFFFFFFFFFFFFF)
#define EU1_SET_ISP_DEF         (0x0000000000000000)

#define EU1_GET_ISP_RESULT      (0x2)
#define EU1_GET_ISP_RESULT_LEN  (0x08)
#define EU1_GET_ISP_RESULT_MIN  (0x0)
#define EU1_GET_ISP_RESULT_MAX  (0xFFFFFFFFFFFFFFFF)
#define EU1_GET_ISP_RESULT_DEF  (0x0000000000000000)

#define EU1_SET_FW_DATA         (0x03)
#define EU1_SET_FW_DATA_LEN     (0x20)      //32bytes
//#define EU1_SET_FW_DATA_MIN   (0x00)
//#define EU1_SET_FW_DATA_MAX   (0xFF)
//#define EU1_SET_FW_DATA_DEF   (0x00)

#define EU1_SET_MMP             (0x04)  //command number
#define EU1_SET_MMP_LEN         (0x08)
#define EU1_SET_MMP_MIN         (0x0)
#define EU1_SET_MMP_MAX         (0xFFFFFFFFFFFFFFFF)
#define EU1_SET_MMP_DEF         (0x0000000000000000)

#define EU1_GET_MMP_RESULT      (0x5)
#define EU1_GET_MMP_RESULT_LEN  (0x08)
#define EU1_GET_MMP_RESULT_MIN  (0x0)
#define EU1_GET_MMP_RESULT_MAX  (0xFFFFFFFFFFFFFFFF)
#define EU1_GET_MMP_RESULT_DEF  (0x0000000000000000)

#define EU1_SET_ISP_EX          (0x6)
#define EU1_SET_ISP_EX_LEN      (0x10)
//#define EU1_SET_ISP_EX_MIN         (0x0)
//#define EU1_SET_ISP_EX_MAX         (0xFFFFFFFFFFFFFFFF)
//#define EU1_SET_ISP_EX_DEF         (0x0000000000000000)

#define EU1_GET_ISP_EX_RESULT      (0x7)
#define EU1_GET_ISP_EX_RESULT_LEN  (0x10)
//#define EU1_GET_ISP_EX_RESULT_MIN  (0x0)
//#define EU1_GET_ISP_EX_RESULT_MAX  (0xFFFFFFFFFFFFFFFF)
//#define EU1_GET_ISP_EX_RESULT_DEF  (0x0000000000000000)

#define EU1_READ_MMP_MEM            (0x08)
#define EU1_READ_MMP_MEM_LEN        (0x10)
//#define EU1_READ_MMP_MEM_MIN         (0x0)
//#define EU1_READ_MMP_MEM_MAX         (0xFFFFFFFFFFFFFFFF)
//#define EU1_READ_MMP_MEM_DEF         (0x0000000000000000)

#define EU1_WRITE_MMP_MEM           (0x09)
#define EU1_WRITE_MMP_MEM_LEN       (0x10)
//#define EU1_WRITE_MMP_MEM_MIN         (0x0)
//#define EU1_WRITE_MMP_MEM_MAX         (0xFFFFFFFFFFFFFFFF)
//#define EU1_WRITE_MMP_MEM_DEF         (0x0000000000000000)

#define EU1_GET_CHIP_INFO      (0xA)
#define EU1_GET_CHIP_INFO_LEN  (0x10)
#define EU1_GET_CHIP_INFO_MIN  (0x0)
#define EU1_GET_CHIP_INFO_MAX  (0xFFFFFFFFFFFFFFFF)
#define EU1_GET_CHIP_INFO_DEF  (0x0000000000000000)

#define EU1_GET_DATA_32         (0x0B)
#define EU1_GET_DATA_32_LEN     (0x20)

#define EU1_SET_DATA_32         (0x0C)
#define EU1_SET_DATA_32_LEN     (0x20)

#define EU1_SET_MMP_CMD16      (0xE)
#define EU1_SET_MMP_CMD16_LEN  (0x10)
#define EU1_SET_MMP_CMD16_MIN  (0x0)
#define EU1_SET_MMP_CMD16_MAX  (0xFFFFFFFFFFFFFFFF)
#define EU1_SET_MMP_CMD16_DEF  (0x0000000000000000)

#define EU1_GET_MMP_CMD16_RESULT      (0xF)
#define EU1_GET_MMP_CMD16_RESULT_LEN  (0x10)
#define EU1_GET_MMP_CMD16_RESULT_MIN  (0x0)
#define EU1_GET_MMP_CMD16_RESULT_MAX  (0xFFFFFFFFFFFFFFFF)
#define EU1_GET_MMP_CMD16_RESULT_DEF  (0x0000000000000000)

#define EU1_ACCESS_CUSTOMER_DATA (0x10)
#define EU1_ACCESS_CUSTOMER_DATA_LEN    (0x20)
//#define EU1_ACCESS_CUSTOMER_DATA_MIN
//#define EU1_ACCESS_CUSTOMER_DATA_MAX
//#define EU1_ACCESS_CUSTOMER_DATA_DEF
#define EU1_ACCESS_CUSTOMER_DATA_RES    (0x01)


MMP_UBYTE eu1_set_isp_val[EU1_SET_MMP_LEN];
MMP_UBYTE eu1_get_isp_result_val[EU1_GET_ISP_RESULT_LEN];
MMP_UBYTE eu1_set_mmp_val[EU1_SET_MMP_LEN];
MMP_UBYTE eu1_get_mmp_result_val[EU1_GET_MMP_RESULT_LEN];
MMP_UBYTE eu1_set_isp_ex_val[EU1_SET_ISP_EX_LEN];
MMP_UBYTE eu1_get_isp_ex_result_val[EU1_GET_ISP_EX_RESULT_LEN];
MMP_UBYTE eu1_get_chip_info_val[EU1_GET_CHIP_INFO_LEN];
MMP_UBYTE eu1_set_mmp_cmd16_val[EU1_SET_MMP_CMD16_LEN];
MMP_UBYTE eu1_get_mmp_cmd16_result_val[EU1_GET_MMP_CMD16_RESULT_LEN];

//ISP IQTOOL
#define ISPIQ_GET_PREVIEW_GAIN_ID   0x00
#define ISPIQ_GET_CAPTURE_GAIN_ID   0x01
#define ISPIQ_GET_PREVIEW_ENGERY_ID 0x02
#define ISPIQ_GET_CAPTURE_ENGERY_ID 0x03
#define ISPIQ_SET_AWB_MODE          0x04
#define ISPIQ_GET_PREVIEW_TEMP_ID   0x05
#define ISPIQ_GET_CAPTURE_TEMP_ID   0x06
#define ISPIQ_SELECT_DBG_TABLE      0x07
#define ISPIQ_SET_DBG_TABLE_BY_INDEX  0x08
#define ISPIQ_GET_DBG_TBL_ROWS      0x09
#define ISPIQ_GET_DBG_TBL_COLS      0x0A
#define ISPIQ_GET_DBG_TBL_TYPE      0x0B
#define ISPIQ_GET_DBG_TBL_MODE      0x0C
#define ISPIQ_GET_DBG_TBL_VALUE     0x0D
#define ISPIQ_GET_DBL_TBL_START_ADDR  0x0E
#define ISPIQ_GET_DBG_TBL_APTOOL_ADDR 0x0F
#define ISPIQ_GET_DBL_TBL_TOTAL_SIZE  0x10
#define ISPIQ_WRITE_MEM_PARAM       0x11
#define ISPIQ_WRITE_MEM             0x12
#define ISPIQ_READ_MEM_PARAM        0x13
#define ISPIQ_READ_MEM              0x14
#define ISPIQ_MOVE_MEM              0x15
#define ISPIQ_SET_AE_ISO            0x16
#define ISPIQ_GET_AWB_GAIN          0x17
#define ISPIQ_GET_LIGHT_COND_VAL    0x18
#define ISPIQ_GET_AE_ENERGY         0x19
#define ISPIQ_SET_IQ_SWITCH         0x20
#define ISPIQ_GET_AE_BASE_SHUTTER   0x21
#define ISPIQ_GET_AWB_TEMPRET       0x26

MMP_ULONG WriteMemAddr = 0;
MMP_ULONG WriteMemCount = 0;
MMP_ULONG ReadMemAddr = 0;
MMP_ULONG ReadMemCount = 0;



#define EU2_CMD1_MIN (0x08)
#define EU2_CMD1_MAX (0x80)
#define EU2_CMD1_DEF (0x5a)
//
// XU1 : AIT internal ISP / MMP control
//
VC_CMD_CFG VC_XU_SET_ISP_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT),
EU1_SET_ISP_LEN,
0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_GET_ISP_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_GET_SUPPORT),
EU1_GET_ISP_RESULT_LEN,
0,0,0,0,0
} ;


VC_CMD_CFG VC_XU_SET_FW_DATA_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT),
EU1_SET_FW_DATA_LEN,
0,0,0,0,0
} ;


VC_CMD_CFG VC_XU_SET_MMP_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT),
EU1_SET_MMP_LEN,
0,0,0,0,0
} ;


VC_CMD_CFG VC_XU_GET_MMP_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_GET_SUPPORT),
EU1_GET_MMP_RESULT_LEN,
0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_SET_ISP_EX_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT),
EU1_SET_ISP_EX_LEN,
0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_GET_ISP_EX_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_GET_SUPPORT),
EU1_GET_ISP_EX_RESULT_LEN,
0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_READ_MMP_MEM_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_GET_SUPPORT),
EU1_READ_MMP_MEM_LEN,
0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_SET_MMP_MEM_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT),
EU1_WRITE_MMP_MEM_LEN,
0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_ACCESS_CUSTOMER_DATA_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT),
EU1_ACCESS_CUSTOMER_DATA_LEN,
0,0,0,0,0
} ;

#if (CUSTOMER == CCN) || (CUSTOMER == LON) || (CUSTOMER == ASU)
//#define CUSTOMER_INIT_FLASH_ADDR   IQ_SETTING_ADDR_IN_FLASH //(0x1e000)
//#define CUSTOMER_INIT_FLASH_SIZE   (0x1000)
//#define SIF_SECTOR_SIZE 1024*4    //4K
//MMP_BYTE  gbNVMCmd = 0;
MMP_USHORT gsNVMAddr = 0;
MMP_BYTE CustomDataRwBuf[EU1_ACCESS_CUSTOMER_DATA_LEN];
#endif

VC_CMD_CFG VC_XU_GET_CHIP_INFO_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_GET_SUPPORT),
EU1_GET_CHIP_INFO_LEN,
0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_GET_DATA_32_CFG = {
(CAP_GET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_GET_SUPPORT),
EU1_GET_DATA_32_LEN,
0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_SET_DATA_32_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT),
EU1_SET_DATA_32_LEN,
0,0,0,0,0
};

VC_CMD_CFG VC_XU_SET_MMP_CMD16_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT),
EU1_SET_MMP_CMD16_LEN,
0,0,0,0,0
} ;

DataExchangeParam gDEParam = {0,0,0,0};

VC_CMD_CFG VC_XU_GET_MMP_CMD16_RESULT_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_CUR_CMD | CAP_GET_DEF_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD | CAP_GET_RES_CMD | CAP_GET_LEN_CMD),
(INFO_SET_SUPPORT | INFO_GET_SUPPORT),
EU1_GET_MMP_CMD16_RESULT_LEN,
0,0,0,0,0
} ;

#define ISP_CMD_DO_AF 1
#define ISP_CMD_SET_FPS 2

MMP_ULONG glIRCutStatus = 0;

//extern MMP_ULONG       VidRecdBitrate;                     ///< current bitrate
static MMP_USHORT input_gainR, input_gainG, input_gainB;
MMP_UBYTE  flip_enable, mirror_enable, black_image;
static MMP_UBYTE  jpeg_quality;
MMP_BOOL gbMirrorFlip_flag = 0;

extern MMP_USHORT Q_Level;
extern MMP_BOOL Mjpeg_Q_En;
MMP_UBYTE XU_Ctrl_StreamID = 0xFF;
#if (SUPPORT_H264MV_MD) // for motion vector	
MMP_ULONG DualStream_setFPS[3] = {30,10,30};   //0:Main stream 1:Local stream
#else
MMP_ULONG DualStream_setFPS[3] = {30,30,30};   //0:Main stream 1:Local stream
#endif
MMP_ULONG DualStream_setBR[2] = {3000000,1000000};  //0:Main stream 1:Local stream
MMP_ULONG MJ_BitRate_Ctrl = 20000;//Dual Stream Ctrl MJPEG Bit Rate

#if (SUPPORT_H264MV_MD)
extern int glMDMotionCnt;
#endif

extern MMP_BOOL gbIsBootComplete;

void usb_vc_eu1_isp_cmd(MMP_UBYTE *cmd)//cmd -> 8byte
{
    MMP_UBYTE vidQuality ;
    MMP_BOOL IsPreviewEnable;
    UVCX_BitRateLayers br_ctl ;

    MMP_ULONG bit_rate;  // Kbps
#if 1
    //RTNA_DBG_Str(0, "isp cmd: ");
    //RTNA_DBG_Byte(0, cmd[0]);
    //RTNA_DBG_Str(0, " ");
    //RTNA_DBG_Byte(0, cmd[1]);
    //RTNA_DBG_Str(0, " ");
    //RTNA_DBG_Byte(0, cmd[2]);
    //RTNA_DBG_Str(0, " ");
    //RTNA_DBG_Byte(0, cmd[3]);
    //RTNA_DBG_Str(0, " ");
    //RTNA_DBG_Byte(0, cmd[4]);
    //RTNA_DBG_Str(0, "\r\n");

    dbg_printf(3, "isp cmd x%02X x%02X x%02X x%02X x%02X\r\n", cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]);
#endif
    //eu1_cmd2_value = EU_ISP_CMD_OK;
    eu1_get_isp_result_val[0] = EU_ISP_CMD_OK;

    switch(cmd[0]){
    case 1:
#ifdef ZDW_BARCODE
	gbIsBootComplete = 1;
#endif

        //AF

#if (SUPPORT_H264MV_MD)
        //ISP_IF_AF_Control(ISP_AF_START);
        #if 1  // debug
        { 
            int MvXTh, MvYTh, CntTh;
            MD_GetMvThreshold(&MvXTh, &MvYTh);
            MD_GetCntTh(&CntTh);   
            eu1_get_isp_result_val[1] = (MMP_UBYTE)glMDMotionCnt;
            eu1_get_isp_result_val[2] = (MMP_UBYTE)(MD_GetMDAreaMaskCount() & 0xFF);
            eu1_get_isp_result_val[3] = (MMP_UBYTE)(MD_GetMDAreaMaskCount() >> 8);
            eu1_get_isp_result_val[4] = (MMP_UBYTE)(CntTh & 0xFF);
            eu1_get_isp_result_val[5] = (MMP_UBYTE)(CntTh >> 8);
            eu1_get_isp_result_val[6] = (MMP_UBYTE)MvXTh;
            eu1_get_isp_result_val[7] = (MMP_UBYTE)MvYTh;
        }
        #endif
#endif

        break;
    case 2:
        //set encoder fps
         {
            extern MMPS_3GPRECD_VIDEO_FORMAT m_VideoFmt;
            MMP_USHORT fps = cmd[1] ;
            if(fps > 30)
                fps = 30 ;
            else if(fps < 5)
                fps = 5;


#if (FPS_CTL == 1)
            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
#if USING_UVCX_VIDEO_CONFIG==1
            if(IsPreviewEnable){
                if(XU_Ctrl_StreamID == 0xFF){
                    if((m_VideoFmt == MMPS_3GPRECD_VIDEO_FORMAT_YUV420) ||
                       (m_VideoFmt == MMPS_3GPRECD_VIDEO_FORMAT_YUV422)) {
                        ISP_IF_AE_SetFPS(cmd[1]);
                    }
                    else {
                        UVCX_SetH264FrameRate(0, 10000000 / fps);
                        if((FRAMEBASE_DUAL_H264 == gbCurH264Type) || (FRAMEBASE_DUAL_H264_MJPEG == gbCurH264Type)){
                            UVCX_SetH264FrameRate(1, 10000000 / fps);
                        }
                        DualStream_setFPS[0] = DualStream_setFPS[1] = DualStream_setFPS[2] = cmd[1];
                    }
                    #if (CUSTOMER == ANW)&&SUPPORT_H264MV_MD
                    if(FRAMEBASE_H264FRAME_MJPEG == gbCurH264Type)
                        DualStream_setFPS[1] = 10;
                    #endif
                }
                else if(XU_Ctrl_StreamID == 0x00){
                    UVCX_SetH264FrameRate(XU_Ctrl_StreamID, (10000000 / fps));
                    DualStream_setFPS[0] = cmd[1];
                }
                else if(XU_Ctrl_StreamID == 0x01){
                    if((FRAMEBASE_DUAL_H264 == gbCurH264Type) || (FRAMEBASE_DUAL_H264_MJPEG == gbCurH264Type)){
                        UVCX_SetH264FrameRate(XU_Ctrl_StreamID, (10000000 / fps));
                        DualStream_setFPS[1] = cmd[1];
                    }
                    else{  
                        DualStream_setFPS[2] = cmd[1];  // Set MJPG frame rate
                    }
                }
                else if(XU_Ctrl_StreamID == 0x02){ 
                    if(FRAMEBASE_DUAL_H264_MJPEG == gbCurH264Type){
                        DualStream_setFPS[2] = cmd[1];  // Set MJPG frame rate
                    }
                    else if(FRAMEBASE_H264FRAME_MJPEG == gbCurH264Type){
                        DualStream_setFPS[1] = cmd[1];  // Set H.264 MV stream frame rate
                    }
                }
                dbg_printf(3, "#%X Set FR. = %d\r\n", XU_Ctrl_StreamID, fps);
            }
            else{
                if(XU_Ctrl_StreamID == 0xFF){
                    gsCurH264Config.dwFrameInterval = (10000000 / fps);
#if XU_FRAMEBASE_CAPTURE
                    gFramebaseCap.orgFramerate = cmd[1];
#endif
                    DualStream_setFPS[0] = DualStream_setFPS[1] = DualStream_setFPS[2] = cmd[1];
                }
                else if(XU_Ctrl_StreamID == 0x00){
                    gsCurH264Config.dwFrameInterval = (10000000 / fps);
                    DualStream_setFPS[0] = cmd[1];
                }
                else if(XU_Ctrl_StreamID == 0x01){
                    gsCurH264Config.dwFrameInterval = (10000000 / fps);
                    DualStream_setFPS[1] = cmd[1];
                }
                else if(XU_Ctrl_StreamID == 0x02){
                    DualStream_setFPS[2] = cmd[1];  // Set MJPG frame rate
                    #if SUPPORT_H264MV_MD
                    DualStream_setFPS[1] = cmd[1];  // Set H.264 MV stream frame rate
                    #endif
                }
                #if (CUSTOMER == ANW)&&SUPPORT_H264MV_MD
                DualStream_setFPS[1] = 10;
                #endif
                dbg_printf(3, "@%X Set FR. = %d\r\n", XU_Ctrl_StreamID, fps);
            }
#else
            if(IsPreviewEnable){
                if(cmd[1] < 5){
                    gsVideoEncodeFPS = 5;
                }
                else if(cmd[1] > 30){
                    gsVideoEncodeFPS = 30;
                }
                else{
                    gsVideoEncodeFPS = cmd[1];
                }
                {
                    MMPF_VIDENC_MAX_FPS_CTL FpsCtl;
                    FpsCtl.ulMaxFpsResolution = gsVideoEncodeFPS * VIDEO_FPS_SCALE;
                    FpsCtl.ulMaxFpsIncreament = VIDEO_FPS_SCALE;

#if USB_FRAMEBASE_DUAL_H264_STREAM
                    MMPF_VIDENC_SetParameter(XU_Ctrl_StreamID, MMPF_VIDENC_ATTRIBUTE_MAX_FPS, (void *) &FpsCtl);
#else
                    MMPF_VIDENC_SetParameter(0, MMPF_VIDENC_ATTRIBUTE_MAX_FPS, (void *) &FpsCtl);
#endif
                }
                DBG_S(3, "Set FPS =");
                DBG_D(3, gsVideoEncodeFPS, 2);
                DBG_S(3, "\r\n");
            }
#endif
#else
            DBG_S(3, "Set FPS =");
            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if(IsPreviewEnable){
                ISP_IF_AE_SetFPS(cmd[1]);
            }
            DBG_S(3, "\r\n");
#endif
        }
        break;
    case 3:
         {
#if 0 //WATCHDOG_RESET_EN==1
            //Test Watch Dog

            MMPF_WD_Kick();

    #if (CUSTOMER == LIT) || (CUSTOMER == NKT)
            GPIO_OutputControl(MOV_TRIG, FALSE);  // only for debug, to measure Watch Dog timer kick time
            MMPF_OS_Sleep(1);
            GPIO_OutputControl(MOV_TRIG, TRUE);  // only for debug, to measure Watch Dog timer kick time
    #endif

            DBG_S(3, "  ===== Watch Dog Reset Testing =====\r\n");

            while(1){
    #if (CUSTOMER == LIT) || (CUSTOMER == NKT)
                GPIO_OutputControl(MOV_TRIG, FALSE);  // only for debug, to measure Watch Dog timer kick time
                GPIO_OutputControl(MOV_TRIG, TRUE);  // only for debug, to measure Watch Dog timer kick time
    #endif
            }
#endif

#if ESD_RECOVERY
             {
                extern MMP_UBYTE gbSensorReInitFlag;

                gbSensorReInitFlag = 1;  // trigger sensor recovery
            }
#endif
        }
        break;
    case 4:
        //Set IDR frame

        USB_ForceH264IDRFrame();

        break;
    case 5:
        // Preview start
        gbUVCDSCCommand = 1;
        MMPF_USBCTL_PostMsg(2, TASK_USB_PRIO, USBCTL_MSG_OTHERS, 0, (void *) NULL);
        //        MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);

        break;
    case 6:
        // Preview stop

        gbUVCDSCCommand = 2;
        MMPF_USBCTL_PostMsg(2, TASK_USB_PRIO, USBCTL_MSG_OTHERS, 0, (void *) NULL);
        //        MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);
        break;
    case 7:
        // change resolution
        //m_usResolType = cmd[1];
        USB_SetVideoResolution(PCAM_NONBLOCKING, cmd[1]);
        //gbUVCDSCCommand = 3;
        //MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);

        break;
    case 8:
        //Set MJPG Quality, level is from 0 to 30
        if((cmd[1] != 0xFF) && (cmd[1] <= 30)){
            usb_set_mjpg_quality_level(cmd[1]);
        }

        // change quality
        vidQuality = cmd[1];
        switch(vidQuality){
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        case 0xff:
            // custom video bit rate
            bit_rate = (MMP_ULONG) (cmd[2] + ((MMP_USHORT) cmd[3] << 8));
            if(bit_rate < 25){
                bit_rate = 25;
            }
            
            dbg_printf(3, "  ** bitrate = %d Kbps\r\n", bit_rate);

#if (FPS_CTL == 1)   // bit rate control API test

            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if(IsPreviewEnable){
#if USING_UVCX_VIDEO_CONFIG==1
                if((XU_Ctrl_StreamID == 0xFF) || (XU_Ctrl_StreamID == 0x00)){
                    br_ctl.wLayerID |= (1 << LAYER_ID_BIT_SHIFT_TEMPORAL); //layer 0
                    br_ctl.dwAverageBitrate = br_ctl.dwPeakBitrate = bit_rate * 1000;
                    UVCX_SetH264BitRate(0, &br_ctl);
                    if(XU_Ctrl_StreamID == 0xFF){
                        UVCX_SetH264BitRate(1, &br_ctl);
                    }
                    MJ_BitRate_Ctrl = bit_rate * DualStream_setFPS[2] * 2 / 8;  // in Kbps
                }
                else{
                    //Dual Stream Ctrl MJPEG Bit Rate
                    if((FRAMEBASE_DUAL_H264 == gbCurH264Type) || (FRAMEBASE_DUAL_H264_MJPEG == gbCurH264Type)){
                        br_ctl.wLayerID |= (1 << LAYER_ID_BIT_SHIFT_TEMPORAL); //layer 0
                        br_ctl.dwAverageBitrate = br_ctl.dwPeakBitrate = bit_rate * 1000;
                        UVCX_SetH264BitRate(1, &br_ctl);
                        if(XU_Ctrl_StreamID == 0x02)
                            MJ_BitRate_Ctrl = bit_rate;  // in Kbps
                    }
                    else{
                        MJ_BitRate_Ctrl = bit_rate;  // in Kbps
                        dbg_printf(3, "Set MJPEG bitrate = %d\r\n", MJ_BitRate_Ctrl);
                    }
                }
#endif
            }
            else{
#if USING_UVCX_VIDEO_CONFIG==1
                if((XU_Ctrl_StreamID == 0xFF) || (XU_Ctrl_StreamID == 0x00)){
                    DualStream_setBR[0] = bit_rate * 1000;
                    if(XU_Ctrl_StreamID == 0xFF)
                        DualStream_setBR[1] = bit_rate * 1000;

                    UVCX_GetH264StartConfig()->dwBitRate = bit_rate * 1000;
                    MJ_BitRate_Ctrl = bit_rate;  // in Kbps
                }
                else{
                    //Dual Stream Ctrl MJPEG Bit Rate
                    DualStream_setBR[1] = bit_rate * 1000;
                    MJ_BitRate_Ctrl = bit_rate;  // in Kbps
                    dbg_printf(3, "Set MJPEG bitrate = %d\r\n", MJ_BitRate_Ctrl);
                }
#endif
            }
#endif
            //USB_SetVideoQuality(PCAM_NONBLOCKING,vidQuality);
            break;
        default:
            ISP_IF_AE_SetFPS(30); // ooxx842
            break;
        }
        /*
                RTNA_DBG_Str(0, "  ** gbVideoEncQualityCustom = ");
                RTNA_DBG_Byte(0, gbVideoEncQualityCustom);
                RTNA_DBG_Str(0, "\r\n");
               // RTNA_DBG_Str(0, "  ** m_usVideoQuality = ");
               // RTNA_DBG_Short(0, m_usVideoQuality);
               // RTNA_DBG_Str(0, "\r\n");
                RTNA_DBG_Str(0, "  ** glCustomTargetSizePerFrame = ");
                MMPF_DBG_Int(glCustomTargetSizePerFrame, -6);
                RTNA_DBG_Str(0, "\r\n");
        */
        //gbUVCDSCCommand = 4;
        //MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);
        break;
    case 9:
        // set flicker mode, 0: auto, 1: 60Hz, 2: 50Hz
        if(cmd[1] == 0x01)
            gbBandFilter = BAND_60HZ;
        else if(cmd[1] == 0x02)
            gbBandFilter = BAND_50HZ;
        else
            gbBandFilter = BAND_60HZ;

        RTNA_DBG_Str(3, "  ** USB Light Freq Set : ");
        RTNA_DBG_Short(3, gbBandFilter);
        RTNA_DBG_Str(3, "\r\n");

        //gbUVCDSCCommand = 5;
        //MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);
        USB_SetPowerLineFreq(PCAM_NONBLOCKING, gbBandFilter);

        break;
    case 10:
         {
            MMP_USHORT Addr;
            MMP_USHORT Val;
            volatile MMP_UBYTE *REG_BASE_B = (volatile MMP_UBYTE *) (0x80000000);
            switch(cmd[1]){
            case 0:
                //MMP register 1 byte read
                Addr = cmd[2] + cmd[3] * 0x100;
                eu1_get_isp_result_val[2] = REG_BASE_B[Addr];
                break;
            case 1:
                //MMP register 1 byte write
                Addr = cmd[2] + cmd[3] * 0x100;
                REG_BASE_B[Addr] = cmd[4];//Value&0xFF;
                break;
            case 2:
                //sensor register 1 byte read
                Addr = cmd[2] + cmd[3] * 0x100;
                gsSensorFunction->MMPF_Sensor_GetReg(Addr, &Val);
                eu1_get_isp_result_val[2] = (MMP_UBYTE) (Val & 0xFF);  // Low byte
                eu1_get_isp_result_val[3] = (MMP_UBYTE) (Val >> 8);  // High byte
                RTNA_DBG_Str(3, "  ** Read Sensor Reg[ ");
                RTNA_DBG_Short(3, Addr);
                RTNA_DBG_Str(3, "] = ");
                RTNA_DBG_Short(3, Val);
                RTNA_DBG_Str(3, "\r\n");
                break;
            case 3:
                //sensor register 1 byte write
                Addr = cmd[2] + cmd[3] * 0x100;
                Val = cmd[4] + cmd[5] * 0x100;
                gsSensorFunction->MMPF_Sensor_SetReg(Addr, Val);
                RTNA_DBG_Str(3, "  ** Write Sensor Reg[ ");
                RTNA_DBG_Short(3, Addr);
                RTNA_DBG_Str(3, "] = ");
                RTNA_DBG_Short(3, Val);
                RTNA_DBG_Str(3, "\r\n");
                break;
            default:
                eu1_get_isp_result_val[1] = EU_ISP_CMD_NOT_SUPPORT;
                break;
            }
        }
        break;
    case 11:
        //get FW ver
         {
            eu1_get_isp_result_val[2] = (gbFwVersion.major >> 8) & 0xFF;
            eu1_get_isp_result_val[3] = gbFwVersion.major & 0xFF;
            eu1_get_isp_result_val[4] = (gbFwVersion.minor >> 8) & 0xFF;
            eu1_get_isp_result_val[5] = gbFwVersion.minor & 0xFF;
            eu1_get_isp_result_val[6] = (gbFwVersion.build >> 8) & 0xFF;
            eu1_get_isp_result_val[7] = gbFwVersion.build & 0xFF;
        }
        break;
    case 12:
        //get FW build date
         {
            eu1_get_isp_result_val[1] = mmpf_buildVersion.szDate[9];
            eu1_get_isp_result_val[2] = mmpf_buildVersion.szDate[10];
            eu1_get_isp_result_val[3] = mmpf_buildVersion.szDate[0];
            eu1_get_isp_result_val[4] = mmpf_buildVersion.szDate[1];
            eu1_get_isp_result_val[5] = mmpf_buildVersion.szDate[2];
            eu1_get_isp_result_val[6] = mmpf_buildVersion.szDate[4];
            eu1_get_isp_result_val[7] = mmpf_buildVersion.szDate[5];
        }
        break;
    case 13:
         {
            //#if USB_UVC_SKYPE==0
#if AIT_MODE_B_XU
            SetH264Mode(cmd[1]);
#endif
        }
        break;
    case 14:
         {
            if(cmd[1]){
                ISP_IF_AE_SetEV(-25);
                ISP_IF_F_SetWDR(255);
                if(glIRCutStatus==2)    //If IRCut En, then WDR use night mode IQ setting
                ISP_IF_IQ_SetSysMode(0);
                else
                ISP_IF_IQ_SetSysMode(2);
                RTNA_DBG_Str(0, "  ** WDR ON  **\r\n");
            }
            else{
                ISP_IF_AE_SetEV(0);
                ISP_IF_F_SetWDR(0);
                ISP_IF_IQ_SetSysMode(1);
                RTNA_DBG_Str(0, "  ** WDR OFF  **\r\n");
            }
        }
        break;
    case 15:
        //Set H264 Rate Control Mode
         {
            MMPF_VIDENC_RC_MODE_CTL RcModeCtl;
            switch(cmd[1]){
            case 0:
                //CBR
                dbg_printf(3, "#CBR\r\n");
                RcModeCtl.RcMode = MMPF_VIDENC_RC_MODE_CBR;
                RcModeCtl.bLayerGlobalRc = MMP_FALSE;
                MMPF_VIDENC_SetParameter(0, MMPF_VIDENC_ATTRIBUTE_RC_MODE, (void *) &RcModeCtl);
                break;
            case 1:
                //VBR
                dbg_printf(3, "#VBR\r\n");
                RcModeCtl.RcMode = MMPF_VIDENC_RC_MODE_VBR;
                RcModeCtl.bLayerGlobalRc = MMP_FALSE;
                MMPF_VIDENC_SetParameter(0, MMPF_VIDENC_ATTRIBUTE_RC_MODE, (void *) &RcModeCtl);
                break;
            case 2:
                //Constant QP
                dbg_printf(3, "#Constant QP\r\n");
                RcModeCtl.RcMode = MMPF_VIDENC_RC_MODE_CQP;
                RcModeCtl.bLayerGlobalRc = MMP_FALSE;
                MMPF_VIDENC_SetParameter(0, MMPF_VIDENC_ATTRIBUTE_RC_MODE, (void *) &RcModeCtl);
                break;
            default:
                eu1_get_isp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                break;
            }
        }
        break;
    case 17:
        // ISP API Set AWB Gain
         {
            switch(cmd[1]){
            case 2:
                //set digital R,G,B gain
                 {
                    if(gbAWB == 0){
                        MMP_ULONG  awbgainbase, gain_r, gain_g, gain_b;

                        input_gainR = (cmd[2] + ((MMP_USHORT) cmd[3] << 8));
                        input_gainG = (cmd[4] + ((MMP_USHORT) cmd[5] << 8));
                        input_gainB = (cmd[6] + ((MMP_USHORT) cmd[7] << 8));

                        dbg_printf(3, "R= 0x%x, G= 0x%x, B= 0x%x\r\n", input_gainR, input_gainG, input_gainB);

                        awbgainbase = ISP_IF_AWB_GetGainBase();
                        gain_r = input_gainR * awbgainbase / 0x100;
                        gain_g = input_gainG * awbgainbase / 0x100;
                        gain_b = input_gainB * awbgainbase / 0x100;

                        //set awb gain parameters
                        //ISP_IF_AWB_SetGains( gain_r,  gain_g,  gain_b);

                        //set awb gain to HW
                        //ISP_IF_AWB_SetDGain();
                    }
                }
                break;
            case 3:
                //get digital R,G,B gain
                 {
                    eu1_get_isp_result_val[2] = LOBYTE(input_gainR);
                    eu1_get_isp_result_val[3] = HIBYTE(input_gainR);
                    eu1_get_isp_result_val[4] = LOBYTE(input_gainG);
                    eu1_get_isp_result_val[5] = HIBYTE(input_gainG);
                    eu1_get_isp_result_val[6] = LOBYTE(input_gainB);
                    eu1_get_isp_result_val[7] = HIBYTE(input_gainB);
                }
                break;
            }
        }
        break;
    case 19:
        // Select XU stream ID
        XU_Ctrl_StreamID = cmd[1]; //DualStream(ex:H264+MJPEG 0:H264 1:MJPEG 0xFF:default)
        dbg_printf(3, "XU Ctrl StreamID = %d\r\n", XU_Ctrl_StreamID);
        break;
    case 0xFF:
        // ISP set command
         {
            switch(cmd[1]){
            case 0:
                if(cmd[2] <= 1){
                    //disable lens shading
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_LS, cmd[2]);
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_CS, cmd[2]);
                    gbLenShadingStatus = cmd[2];
                }
                else if(cmd[2] == 0x80){
                    //Luma shadding enable/disable , controlled by cmd[3], 0=off, 1=on
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_LS, cmd[3]);
                }
                else if(cmd[2] == 0x81){
                    //Chroma shadding enable/disable, controlled by cmd[3], 0=off, 1=on
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_CS, cmd[3]);
                }
                break;
            case 1:
                if(cmd[2] <= 1){
                    //disable denoise
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_NR, cmd[2]);
                    gbDeNoiseStatus = cmd[2];
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;
            case 2:
                if(cmd[2] <= 1){
                    //enable gamma
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_GC8, cmd[2]);
                    gbGammaStatus = cmd[2];
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;
            case 3:
                if(cmd[2] <= 1){
                    //enable color matrix
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_CC, cmd[2]);
                    gbColorMatrixStatus = cmd[2];
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;
            case 4:
                if(cmd[2] <= 1){
                    //enable edge enhancement
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_EE, cmd[2]);
                    gbEdgeEnhancementStatus = cmd[2];
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;
            case 5:
                if(cmd[2] <= 1){
                    //enable AE
                    //Set_AEEnable(0);
                    gbAEStatus = cmd[2];
                    USB_EnableAE(PCAM_NONBLOCKING, gbAEStatus);
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }

                break;
            case 6:
                if(cmd[2] <= 1){
                    gbAWBStatus = cmd[2];
                    USB_SetAWBMode(PCAM_NONBLOCKING, gbAWBStatus);
                }
                else if(cmd[2] <= 3){
                    //2: disable AWBG 3:enable AWBG
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_AWBG, cmd[2] - 2);
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;
            case 7:
                if(cmd[2] < 9){
                    gsSharpness = cmd[2];
                    USB_SetSharpness(PCAM_NONBLOCKING, (MMP_BYTE) (gsSharpness - 4));
                }
                break;

            case 8:
                //disable/enable AF
            case 9:
                //get afacc
                break;
            case 0x0B:
                //set image effect
                 {
                    //  ISP_IMAGE_EFFECT_NORMAL         = 0,
                    //  ISP_IMAGE_EFFECT_GREY           = 1,
                    //  ISP_IMAGE_EFFECT_SEPIA          = 2,
                    //  ISP_IMAGE_EFFECT_NEGATIVE       = 3,
                    //  ISP_IMAGE_EFFECT_ANTIQUE        = 4,
                    //  ISP_IMAGE_EFFECT_WATERCOLOR     = 5,
                    //  ISP_IMAGE_EFFECT_RED            = 11,
                    //  ISP_IMAGE_EFFECT_GREEN          = 12,
                    //  ISP_IMAGE_EFFECT_BLUE           = 13,
                    //  ISP_IMAGE_EFFECT_YELLOW         = 15,
                    //  ISP_IMAGE_EFFECT_CARTOON        = 16,
                    //  ISP_IMAGE_EFFECT_EMBOSS         = 17,
                    //  ISP_IMAGE_EFFECT_OIL            = 18,
                    //  ISP_IMAGE_EFFECT_BW             = 19,
                    //  ISP_IMAGE_EFFECT_SKETCH         = 20,
                    //  ISP_IMAGE_EFFECT_CRAYONE        = 21,
                    //  ISP_IMAGE_EFFECT_WHITEBOARD     = 22,
                    //  ISP_IMAGE_EFFECT_BLACKBOARD     = 23,
                    //  ISP_IMAGE_EFFECT_VIVID          = 24,
                    ISP_IF_F_SetImageEffect(cmd[2]);
                }
                break;
            case 0x0C:
                //3A control
                 {
                    //cmd[2] : select algorithm type
                    //cmd[3] : enable(1)/disable(0)
                    ISP_IF_3A_SetSwitch(cmd[2], cmd[3]);
                }
                break;
            case 0x0D:
                //Color Effect control
                 {
                    //cmd[2] : select algorithm type
                    ISP_IF_F_SetImageEffect(cmd[2]);
                }
                break;
            case 0x0E:
                // Disable/Enable Bad Pixel Compensation
                if(cmd[2] <= 1){
                    //disable dpc
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_DPC, cmd[2]);
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;

            case 0x11:
                // ISP API Set Misc Setting
                 {
                    #if OS_CRITICAL_METHOD == 3
                    OS_CPU_SR   cpu_sr = 0;
                    #endif
                    //Moved to VIF_INT_FRM_END to execute
                    if((flip_enable == (cmd[2]&0x01))&&(mirror_enable == ((cmd[2]&0x02)>>1))) {
                        dbg_printf(0, "skip mirror/flip\r\n");
                        break;
                    }
                    IRQ_LOCK(
                        flip_enable = cmd[2] & 0x01;
                        mirror_enable = (cmd[2] & 0x02) >> 1;
                        black_image = (cmd[2] & 0x04) >> 2;
                        gbMirrorFlip_flag = 1;
                    );
                    dbg_printf(3, "Flip = %d, Mirror = %d, black = %d\r\n", flip_enable, mirror_enable, black_image);
                }
                break;
            case 0x12:
                // ISP API Get Misc Setting
                 {
                    eu1_get_isp_result_val[2] = (flip_enable | (mirror_enable << 1) | (black_image << 2));
                }
                break;
            case 0x13:
                // ISP API Set MJPEG quality
                 {
                    jpeg_quality = cmd[2];
                    if(jpeg_quality < 0x10)
                        usb_set_mjpg_quality(0x10);
                    else
                        usb_set_mjpg_quality((MMP_ULONG) jpeg_quality);

                    if(cmd[2] < 42)
                        Q_Level = 0;
                    else if(cmd[2] < 84)
                        Q_Level = 1;
                    else
                        Q_Level = 2;
                    Mjpeg_Q_En = 1;
                    dbg_printf(3, "JPEG quality = 0x%x\r\n", jpeg_quality);
                }
                break;
            case 0x14:
                // ISP API Get MJPEG quality
                 {
                    eu1_get_isp_result_val[2] = jpeg_quality;
                }
                break;
            case 0x15:
                //set flash light
                break;
            case 0x16:
                //static defect cpmpensation
                if(cmd[2] <= 1){
                    //enable dpc
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_SDC, cmd[2]);
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;
            case 0x17:
                //black level compensation
                if(cmd[2] <= 1){
                    //enable dpc
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_BLC, cmd[2]);
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;
            case 0x18:
                //UV CCM
                if(cmd[2] <= 1){
                    //enable dpc
                    ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_UVM12, cmd[2]);
                }
                else{
                    eu1_get_isp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
                }
                break;
            /*case 0x19:
                //Set shading table ID
                if(cmd[2] > 0 && cmd[2] < 0xFF) //set by ID
                {
                    //if cmd[2] == 0, return to default
                    ISP_IF_CALI_SetLSMode(cmd[2] - 1);
                }
                else if(cmd[2] == 0){
                    //back to default
                }
                else if(cmd[2] == 0xFF){
                    //set by color temperature
                    MMP_USHORT ColorTemp;
                    ColorTemp = cmd[3] + (cmd[4] << 8);
                    //waiting for new isp api
                }
                break;*/
            case 0x20:
                //set iso
                 {
                    MMP_USHORT Iso = cmd[2] + (cmd[3] << 8);
                    ISP_IF_AE_SetISO(Iso);
                }
                break;
            /*case 0x21:
                //Scene Mode control
                 {
                    //cmd[2] : select algorithm type
#if SUPPORT_ISP_CALIBRATION_FUNCTION
                    if(ISP_SCENE_MANUAL9 == cmd[2]){
                        //special manual mode for calibration
#if 1
                        //turn off anything but BLC
                        MMP_USHORT i;
                        for(i = 0;i < ISP_IQ_MODULE_NUM;++i){
                            if(i != ISP_IQ_MODULE_BLC){
                                ISP_IF_IQ_SetSwitch(i, 0);
                            }
                        }
#else
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_SDC, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_BCG, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_AEG, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_LS, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_CS, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_DPC, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_AWBG, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_NR, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_EE, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_UVM12, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_CC, 0);
                        ISP_IF_IQ_SetSwitch(ISP_IQ_MODULE_GC8, 0);
#endif
                        MMPF_Scaler_SetOutputColor(MMPF_SCALER_PATH_0, MMP_TRUE, MMPF_SCALER_COLRMTX_FULLRANGE);
                        ISP_IF_AE_SetEV(100);
                    }
                    else
                    #endif
                    {
                        ISP_IF_F_SetScene(cmd[2]);
                    }
                }
                break;*/
            case 0x22:
                //AE Metering Mode control
                 {
                    //cmd[2] : select algorithm type
                    ISP_IF_AE_SetMetering(cmd[2]);
                }
                break;
            case 0x23:
                //AE Exposure value
                {
                    //cmd[2] : -250 ~ 250
                    MMP_ULONG glEV = (cmd[2]<<8) + cmd[3];
                    if(glEV > 0x00FA) {
                        glEV = (~glEV + 1) & 0xFF;  //ISP SetEV function is 32Bit
                        ISP_IF_AE_SetEV(-glEV);
                    }
                    else {
                        ISP_IF_AE_SetEV(glEV);
            }
                    dbg_printf(3,"Set EV : %d\r\n",glEV);
        }
        break;
            case 0x24:
                //AE Exposure time
                {
                    MMP_ULONG AE_time = (cmd[2]<<8) + cmd[3];   //1~1000ms
                    MMP_ULONG Shutter_line = AE_time *  ISP_IF_AE_GetVsync() / 1000;
                    MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
                    if(IsPreviewEnable ) {
                        gsSensorFunction->MMPF_Sensor_SetSensorShutter(Shutter_line, ISP_IF_AE_GetVsync());
                        dbg_printf(3,"Set Exposure time : %d\r\n",Shutter_line);
                    }
                }
                break;
            #if BIND_SENSOR_OV9710
            case 0x25:
                //Control AE speed
                {
                    extern ISP_UINT32 frame_div;
                    if(cmd[2]<1)
                        cmd[2] = 1;
                    if (cmd[2]>10)
                        cmd[2] = 10;
                    frame_div = cmd[2] + 2; //Because the sensor DoAE have three case, so the minimum of three.
                    dbg_printf(3,"Set AE speed level : %d\r\n",cmd[2]);
                }
                break;
            case 0x26:
                //Control Privacy
                {
                    //Must verify whether IQ shading tune into 7x5
                    //cmd[2] : 1:Enable 0:Disable
                    //cmd[3] : Privacy mask array(0~34)(WxH:7x5)
                    extern ISP_UINT8 en_flag,privacymask[35];
                    privacymask[cmd[3]] = cmd[2];
                    en_flag = 1;
                    dbg_printf(3,"Enable[%d] Privacy mask number is %d!\r\n",cmd[2],cmd[3]);
                }
                break;
            #endif
            case 0x27:
                //IR Cut Status
                {
                    //cmd[2] : Reserved
                    //cmd[3] : 0: Default 1: Day mode 2: Night mode
                    glIRCutStatus = cmd[3];
                    if(glIRCutStatus==2) {
                        ISP_IF_F_SetSaturation(-128);
                        ISP_IF_IQ_SetSysMode(2);
                        //If AE set system mode is 1, sync correction Sensor_PreviewMode() {ISP_IF_AE_SetMinFPSx10(80);}
                    }
                    else {
                        ISP_IF_F_SetSaturation(0);
                        ISP_IF_IQ_SetSysMode(1);
                    }
                    dbg_printf(3,"IR Cut status[%d]\r\n",cmd[3]);
                }
                break;
            }
        }
        break;
    case 0x7F:  // ISP get command
         {
            switch(cmd[1]){
            case 0:
                eu1_get_isp_result_val[2] = gbLenShadingStatus;
                break;
            case 1:
                eu1_get_isp_result_val[2] = gbDeNoiseStatus;
                break;
            case 2:
                eu1_get_isp_result_val[2] = gbGammaStatus;
                break;
            case 3:
                eu1_get_isp_result_val[2] = gbColorMatrixStatus;
                break;
            case 4:
                eu1_get_isp_result_val[2] = gbEdgeEnhancementStatus;
                break;
            case 5:
                eu1_get_isp_result_val[2] = gbAEStatus;
                break;
            case 6:
                eu1_get_isp_result_val[2] = gbAWBStatus;
                break;
            case 7:
                eu1_get_isp_result_val[2] = gsSharpness;
                break;
            case 8:
                //get FPS
                eu1_get_isp_result_val[2] = gsVideoEncodeFPS;
                break;
            case 9:
                //get Default FICKER setting
                eu1_get_isp_result_val[2] = gbBandFilter;
                break;
            case 10:
                //get Current FICKER setting
                eu1_get_isp_result_val[2] = gbBandFilter;
                break;
            }
        }
        break;
    default:
        //eu1_cmd2_value = EU_ISP_CMD_NOT_SUPPORT;
        eu1_get_isp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
        break;
    }
}

#if USE_RESET_RANGE
/// reset min, max and resolution
void usb_vc_cmd_reset_range(VC_CMD_CFG * const cfg)
{
    cfg->dwMinVal = 0;
    cfg->dwMaxVal = 0;
    cfg->dwResVal = 0;
}
#endif



//AIT commands
void usb_vc_eu1_cs(MMP_UBYTE req)
{
    MMP_UBYTE cs;//,cap;
    //    MMP_USHORT i;
    //AITPS_USB_CTL pUSB_CTL = AITC_BASE_USBCTL;

    cs = (UsbRequestPayload_wValue >> 8);

    UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);

    switch(cs){
    case EU1_SET_ISP:
         {
#if USE_RESET_RANGE
            usb_vc_cmd_reset_range(&VC_XU_SET_ISP_CFG);
#else
            VC_XU_SET_ISP_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwMinVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
#endif
            //RTNA_DBG_Str(0,"EU1_SET_ISP\r\n");
            usb_vc_cmd_cfg(req, &VC_XU_SET_ISP_CFG, 0);
            break;
        }
    case EU1_GET_ISP_RESULT:
         {
#if USE_RESET_RANGE
            usb_vc_cmd_reset_range(&VC_XU_SET_ISP_CFG);
#else
            VC_XU_SET_ISP_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwMinVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
#endif
            //RTNA_DBG_Str(0,"EU1_GET_ISP\r\n");
            usb_vc_cmd_cfg(req, &VC_XU_GET_ISP_CFG, (CMD_VALUE) eu1_get_isp_result_val);
            break;
        }
        //Get ISP Api result
    case EU1_SET_FW_DATA:
         {
#if USE_RESET_RANGE
            usb_vc_cmd_reset_range(&VC_XU_SET_ISP_CFG);
#else
            VC_XU_SET_ISP_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwMinVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
#endif
            VC_XU_SET_ISP_CFG.dwCurVal = 0;//(MMP_ULONG)resVal ;
            //RTNA_DBG_Str(0,"EU1_SET_FW_DATA\r\n");
            usb_vc_cmd_cfg(req, &VC_XU_SET_FW_DATA_CFG, 0);
            break;
        }
    case EU1_SET_MMP:
         {
#if USE_RESET_RANGE
            usb_vc_cmd_reset_range(&VC_XU_SET_ISP_CFG);
#else
            VC_XU_SET_ISP_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwMinVal = 0;
            VC_XU_SET_ISP_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
#endif

            //RTNA_DBG_Str(0,"EU1_SET_MMP\r\n");
            usb_vc_cmd_cfg(req, &VC_XU_SET_MMP_CFG, 0);
            break;
        }
    case EU1_GET_MMP_RESULT:
         {
#if USE_RESET_RANGE
            usb_vc_cmd_reset_range(&VC_XU_SET_ISP_CFG);
#else
            VC_XU_SET_ISP_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
#endif
            //RTNA_DBG_Str(0,"EU1_GET_MMP_RESULT\r\n");
            usb_vc_cmd_cfg(req, &VC_XU_GET_MMP_CFG, (CMD_VALUE) eu1_get_mmp_result_val);
            break;
        }
    case EU1_SET_ISP_EX:
         {
#if USE_RESET_RANGE
            usb_vc_cmd_reset_range(&VC_XU_SET_ISP_EX_CFG);
#else
            VC_XU_SET_ISP_EX_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_EX_CFG.dwMinVal = 0;//(MMP_ULONG)maxVal
            VC_XU_SET_ISP_EX_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
#endif
            //RTNA_DBG_Str(0,"EU1_SET_ISP_EX\r\n");
            usb_vc_cmd_cfg(req, &VC_XU_SET_ISP_EX_CFG, 0);
            break;
        }
    case EU1_GET_ISP_EX_RESULT:
         {
#if USE_RESET_RANGE
            usb_vc_cmd_reset_range(&VC_XU_SET_ISP_EX_CFG);
#else
            VC_XU_SET_ISP_EX_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_EX_CFG.dwMinVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_ISP_EX_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
#endif
            //RTNA_DBG_Str(0,"EU1_GET_ISP_EX\r\n");
            usb_vc_cmd_cfg(req, &VC_XU_GET_ISP_EX_CFG, (CMD_VALUE) eu1_get_isp_ex_result_val);
            break;
        }

    case EU1_READ_MMP_MEM:
         {
#if 0
    MMP_USHORT i;
    //get isp command 16 BYTES
    switch(req) {
    //case SET_CUR_CMD:
    //    USBOutPhase = req;
    //    USBOutData = 1;
    //    break;
    case GET_CUR_CMD:
    {
        MMP_UBYTE n;
        MMP_UBYTE rlen;
        USBInPhase = req;
        USBEP0TxCnt = EU1_READ_MMP_MEM_LEN;
        if(ReadMemCount>EU1_READ_MMP_MEM_LEN)
            rlen = EU1_READ_MMP_MEM_LEN;
        else
            rlen = ReadMemCount;
        ReadMemCount -= rlen;
        for(n=0;n<16;++n)
        {
              //if(n>=0 && n<8)
              //    pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = n;//+0xA0;
              //else
              //    pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = ((MMP_BYTE*)ReadMemAddr)[n];
              if(n<rlen)
                    pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = ((MMP_BYTE*)ReadMemAddr)[n];
              else
                pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0;
        }
        ReadMemAddr += rlen;
        //RTNA_DBG_Str(0,"Read MMP MEM\r\n");
        usb_ep0_in();
        break;
    }
    case GET_INFO_CMD:
        USBInPhase = req;
        cap = INFO_GET_SUPPORT;//INFO_SET_SUPPORT;//INFO_GET_SUPPORT;//|INFO_SET_SUPPORT;
        USBEP0TxCnt = 0x01;
        pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = cap;
        usb_ep0_in();
        break;
    case GET_DEF_CMD:
        USBInPhase = req;
        USBEP0TxCnt = EU1_READ_MMP_MEM_LEN;//0x2;//0x03;
        for(i = 0;i < EU1_READ_MMP_MEM_LEN;++i)
            pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0x00;
        usb_ep0_in();
        break;
    case GET_MIN_CMD:
        USBInPhase = req;
        USBEP0TxCnt = EU1_READ_MMP_MEM_LEN;//0x2;//0x03;
        for(i = 0;i < EU1_READ_MMP_MEM_LEN;++i)
            pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0x00;
        usb_ep0_in();
        break;
    case GET_MAX_CMD:
        USBInPhase = req;
        USBEP0TxCnt = EU1_READ_MMP_MEM_LEN;//0x2;//0x03;
        for(i = 0;i < EU1_READ_MMP_MEM_LEN;++i)
            pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0xFF;
        usb_ep0_in();
        break;
    case GET_RES_CMD:
        USBInPhase = req;
        USBEP0TxCnt = EU1_READ_MMP_MEM_LEN;//0x2;//0x03;
        pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0x01;
        for(i = 0;i < EU1_GET_ISP_EX_RESULT_LEN - 1;++i)
            pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0x00;
        usb_ep0_in();
        break;
    case GET_LEN_CMD:
        USBInPhase = req;
        USBEP0TxCnt = 0x02;
        pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = EU1_READ_MMP_MEM_LEN & 0xFF;
        pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = (EU1_READ_MMP_MEM_LEN >> 8) & 0xFF;
        usb_ep0_in();
        break;
    default:
        // un-support
        UsbWriteEp0CSR(SET_EP0_SENDSTALL);
        gbVCERRCode = CONTROL_INVALID_REQUEST;
        break;
    }
#else
    MMP_UBYTE buf[EU1_READ_MMP_MEM_LEN];
    if(req == GET_CUR_CMD)
    {
        MMP_UBYTE n;
        MMP_UBYTE rlen;
        USBInPhase = req;
        if(ReadMemCount>EU1_READ_MMP_MEM_LEN)
            rlen = EU1_READ_MMP_MEM_LEN;
        else
            rlen = ReadMemCount;
        ReadMemCount -= rlen;
        for(n=0;n<16;++n)
        {
              if(n<rlen)
                    buf[n] = ((MMP_BYTE*)ReadMemAddr)[n];
              else
                buf[n] = 0;
        }
        ReadMemAddr += rlen;
    }
#if USE_RESET_RANGE
    usb_vc_cmd_reset_range(&VC_XU_READ_MMP_MEM_CFG);
#else
    VC_XU_READ_MMP_MEM_CFG.dwMaxVal = 0;
    VC_XU_READ_MMP_MEM_CFG.dwMinVal = 0;
    VC_XU_READ_MMP_MEM_CFG.dwResVal = 0;
#endif
    usb_vc_cmd_cfg(req,&VC_XU_READ_MMP_MEM_CFG, (CMD_VALUE)buf);
#endif
            break;
        }
    case EU1_WRITE_MMP_MEM:
         {
#if 0
    MMP_USHORT i;
    switch(req) {
    case SET_CUR_CMD:
        USBOutPhase = req;
        USBOutData = 1;
        break;
    case GET_INFO_CMD:
        USBInPhase = req;
        cap = INFO_SET_SUPPORT;//INFO_GET_SUPPORT;//|INFO_SET_SUPPORT;
        USBEP0TxCnt = 0x01;
        pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = cap;
        usb_ep0_in();
        break;
    case GET_DEF_CMD:
        USBInPhase = req;
        USBEP0TxCnt = EU1_WRITE_MMP_MEM_LEN;//0x2;//0x03;
        for(i = 0;i < EU1_WRITE_MMP_MEM_LEN;++i)
            pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0x00;
        usb_ep0_in();
        break;
    case GET_MIN_CMD:
        USBInPhase = req;
        USBEP0TxCnt = EU1_WRITE_MMP_MEM_LEN;//0x2;//0x03;
        for(i = 0;i < EU1_WRITE_MMP_MEM_LEN;++i)
            pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0x00;
        usb_ep0_in();
        break;
    case GET_MAX_CMD:
        USBInPhase = req;
        USBEP0TxCnt = EU1_WRITE_MMP_MEM_LEN;//0x2;//0x03;
        for(i = 0;i < EU1_WRITE_MMP_MEM_LEN;++i)
            pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0xFF;
        usb_ep0_in();
        break;
    case GET_RES_CMD:
        USBInPhase = req;
        USBEP0TxCnt = EU1_WRITE_MMP_MEM_LEN;//0x2;//0x03;
        pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0x01;
        for(i = 0;i < EU1_WRITE_MMP_MEM_LEN - 1;++i)
            pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = 0x00;
        usb_ep0_in();
        break;
    case GET_LEN_CMD:
        USBInPhase = req;
        USBEP0TxCnt = 0x02;
        pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = EU1_WRITE_MMP_MEM_LEN & 0xFF;
        pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B = (EU1_WRITE_MMP_MEM_LEN >> 8) & 0xFF;
        usb_ep0_in();
        break;
    default:
        // un-support
        UsbWriteEp0CSR(SET_EP0_SENDSTALL);
        gbVCERRCode = CONTROL_INVALID_REQUEST;
        break;
    }
#else
#if USE_RESET_RANGE
    usb_vc_cmd_reset_range(&VC_XU_SET_MMP_MEM_CFG);
#else
    VC_XU_SET_MMP_MEM_CFG.dwMaxVal = 0;
    VC_XU_SET_MMP_MEM_CFG.dwMinVal = 0;
    VC_XU_SET_MMP_MEM_CFG.dwResVal = 0;
#endif
    usb_vc_cmd_cfg(req,&VC_XU_SET_MMP_MEM_CFG, 0);
#endif
            break;
        }

    case EU1_GET_CHIP_INFO:
         {
            VC_XU_GET_CHIP_INFO_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_GET_CHIP_INFO_CFG.dwMinVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_GET_CHIP_INFO_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;

            //RTNA_DBG_Str(0,"EU1_GET_CHIP_INFO\r\n");
#if 1
             {
                OS_MemCopy(eu1_get_chip_info_val, (MMP_UBYTE *) "PYTHON_V2B\0\0\0\0\0", 15);
            }
#else
            eu1_get_chip_info_val[0] = 'P';
            eu1_get_chip_info_val[1] = 'Y';
            eu1_get_chip_info_val[2] = 'T';
            eu1_get_chip_info_val[3] = 'H';
            eu1_get_chip_info_val[4] = 'O';
            eu1_get_chip_info_val[5] = 'N';
            eu1_get_chip_info_val[6] = '_';
            eu1_get_chip_info_val[7] = 'V';
            eu1_get_chip_info_val[8] = '2';
            eu1_get_chip_info_val[9] = 'B';
            eu1_get_chip_info_val[10] = 0;
            eu1_get_chip_info_val[11] = 0;
            eu1_get_chip_info_val[12] = 0;
            eu1_get_chip_info_val[13] = 0;
            eu1_get_chip_info_val[14] = 0;
            eu1_get_chip_info_val[15] = 0;
#endif
            usb_vc_cmd_cfg(req, &VC_XU_GET_CHIP_INFO_CFG, (CMD_VALUE) & eu1_get_chip_info_val[0]);
            break;
        }

    case EU1_GET_DATA_32:
         {
            MMP_UBYTE curVal[EU1_GET_DATA_32_LEN];
            /*
            VC_XU_GET_DATA_32_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_GET_DATA_32_CFG.dwMinVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_GET_DATA_32_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
            VC_XU_GET_DATA_32_CFG.dwCurVal = 0;//(MMP_ULONG)curVal ;
            */
            if(req == GET_CUR_CMD){
                if(gDEParam.cur_offset < gDEParam.data_len){
                    MMP_UBYTE i,len;
                    len = (gDEParam.data_len - gDEParam.cur_offset > EU1_GET_DATA_32_LEN) ?
                          EU1_GET_DATA_32_LEN :
                          (gDEParam.data_len - gDEParam.cur_offset);
                    for(i = 0;i < len;++i){
                        curVal[i] = gDEParam.ptr[gDEParam.cur_offset + i];
                    }
                    gDEParam.cur_offset += len;
                }
                VC_XU_GET_DATA_32_CFG.dwCurVal = (CMD_VALUE) curVal;
            }

            usb_vc_cmd_cfg(req, &VC_XU_GET_DATA_32_CFG, VC_XU_GET_DATA_32_CFG.dwCurVal);
            break;
        }
    case EU1_SET_DATA_32:
         {
            VC_XU_SET_DATA_32_CFG.dwMaxVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_DATA_32_CFG.dwMinVal = 0;//(MMP_ULONG)maxVal ;
            VC_XU_SET_DATA_32_CFG.dwResVal = 0;//(MMP_ULONG)resVal ;
            VC_XU_SET_DATA_32_CFG.dwCurVal = 0;//(MMP_ULONG)maxVal ;

            //RTNA_DBG_Str(0,"EU1_SET_FW_DATA\r\n");
            usb_vc_cmd_cfg(req, &VC_XU_SET_DATA_32_CFG, 0);
            break;
        }

    case EU1_SET_MMP_CMD16:
         {
#if 0
    MMP_UBYTE maxVal[EU1_SET_MMP_CMD16_LEN] ;
    MMP_UBYTE resVal[EU1_SET_MMP_CMD16_LEN] ;
    MMP_UBYTE i ;
    for(i=0;i<EU1_SET_MMP_CMD16_LEN;i++) {
        maxVal[i] = 0xFF ;
        resVal[i] = 0x00 ;
    }
    resVal[0] = 0x01 ;
    VC_XU_SET_MMP_CMD16_CFG.dwMaxVal = (MMP_ULONG)maxVal ;
    VC_XU_SET_MMP_CMD16_CFG.dwResVal = (MMP_ULONG)resVal ;
    usb_vc_cmd_cfg(req,&VC_XU_SET_MMP_CMD16_CFG, 0);
#else
    VC_XU_SET_MMP_CMD16_CFG.dwMinVal = 0 ;
    VC_XU_SET_MMP_CMD16_CFG.dwMaxVal = 0 ;
    VC_XU_SET_MMP_CMD16_CFG.dwResVal = 0 ;
    usb_vc_cmd_cfg(req,&VC_XU_SET_MMP_CMD16_CFG, 0);
#endif
            break;
        }
    case EU1_GET_MMP_CMD16_RESULT:
         {
#if 0
    MMP_UBYTE maxVal[EU1_GET_MMP_CMD16_RESULT_LEN] ;
    MMP_UBYTE resVal[EU1_GET_MMP_CMD16_RESULT_LEN] ;
    MMP_UBYTE i ;
    for(i=0;i<EU1_GET_MMP_CMD16_RESULT_LEN;i++) {
        maxVal[i] = 0xFF ;
        resVal[i] = 0x00 ;
    }
    resVal[0] = 0x01 ;
    VC_XU_GET_MMP_CMD16_RESULT_CFG.dwMaxVal = (MMP_ULONG)maxVal ;
    VC_XU_GET_MMP_CMD16_RESULT_CFG.dwResVal = (MMP_ULONG)resVal ;
    usb_vc_cmd_cfg(req,&VC_XU_GET_MMP_CMD16_RESULT_CFG, (CMD_VALUE)eu1_get_mmp_cmd16_result_val);
#else
    VC_XU_GET_MMP_CMD16_RESULT_CFG.dwMinVal = 0 ;
    VC_XU_GET_MMP_CMD16_RESULT_CFG.dwMaxVal = 0 ;
    VC_XU_GET_MMP_CMD16_RESULT_CFG.dwResVal = 0 ;
    usb_vc_cmd_cfg(req,&VC_XU_GET_MMP_CMD16_RESULT_CFG, (CMD_VALUE)eu1_get_mmp_cmd16_result_val);
#endif
            break;
        }

#if (CUSTOMER == CCN) || (CUSTOMER == LON) || (CUSTOMER == ASU)
    case EU1_ACCESS_CUSTOMER_DATA:
         {
            VC_XU_ACCESS_CUSTOMER_DATA_CFG.dwMaxVal = 0;
            VC_XU_ACCESS_CUSTOMER_DATA_CFG.dwMinVal = 0;
            VC_XU_ACCESS_CUSTOMER_DATA_CFG.dwResVal = 0;
            VC_XU_ACCESS_CUSTOMER_DATA_CFG.dwCurVal = 0;
            if(req == GET_CUR_CMD){
                //read table

                //MMPF_SIF_Init();
                if(USB_ResetFlash()){
#if (EN_DBGLOG_FOR_FLASH)
                    RTNA_DBG_Str(0, "\r\nSIF init error !!\r\n");
#endif
                }
                MMPF_SIF_ReadDataEx(CUSTOMER_INIT_FLASH_ADDR + gsNVMAddr, (MMP_ULONG) CustomDataRwBuf + 3,
                                    EU1_ACCESS_CUSTOMER_DATA_LEN - 3);
                CustomDataRwBuf[0] = 0;//'A';
                CustomDataRwBuf[1] = 0;//'I';
                CustomDataRwBuf[2] = 0;//'T';
                /*
                RTNA_DBG_Str(3,"Read Table Addr:");
                RTNA_DBG_Long(3,gsNVMAddr);
                RTNA_DBG_Str(3,"\r\n Data=");
                RTNA_DBG_Byte(3,CustomDataRwBuf[3]);
                RTNA_DBG_Byte(3,CustomDataRwBuf[4]);
                RTNA_DBG_Byte(3,CustomDataRwBuf[5]);
                RTNA_DBG_Byte(3,CustomDataRwBuf[6]);
                RTNA_DBG_Str(3,"\r\n");
                */
            }
            usb_vc_cmd_cfg(req, &VC_XU_ACCESS_CUSTOMER_DATA_CFG, (CMD_VALUE) CustomDataRwBuf);
            break;
        }
#endif

        //case XU_CONTROL_UNDEFINED:
    default:
        // un-support
#if 0
UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
UsbWriteEp0CSR(SET_EP0_SENDSTALL);
gbVCERRCode = CONTROL_INVALID_CONTROL;
#else
usb_vc_stall_rx(CONTROL_INVALID_CONTROL);
#endif
        break;
    }
}


MMP_ERR USB_DownloadFWData(MMP_UBYTE *data, MMP_USHORT len);

AitH264FrameList H264FormatList =
{
sizeof(AitH264FrameList),   //length
NUM_FRAME_DESC,
{
#if SKYPE_MODE_B
// frame desc 1
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_YUY2,     //payload format
0,                          //index
160,                        //h264 width
120,                        //h264 height
160,                        //local width
120,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       120,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 2
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_YUY2,     //payload format
1,                          //index
320,                        //h264 width
240,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 3
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_YUY2,     //payload format
2,                          //index
640,                        //h264 width
360,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       200,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 4
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_YUY2,     //payload format
3,                          //index
640,                        //h264 width
480,                        //h264 height
320,                        //local width
240,                        //local width
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 5
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_YUY2,     //payload format
4,                          //index
768,                        //h264 width
480,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       200,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 6
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_YUY2,     //payload format
5,                          //index
1280,                       //h264 width
720,                        //h264 height
384,                        //local width
216,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       216,                        //local height
5,                          //min fps
30                          //max fps

},
#endif
#if USB_MJPEGH264_STREAM
// frame desc 7
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 0,                          //index
160,                        //h264 width
120,                        //h264 height
160,                        //local width
120,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       120,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 8
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 1,                          //index
320,                        //h264 width
240,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 9
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 2,                          //index
352,                        //h264 width
288,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 10
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 3,                          //index
640,                        //h264 width
360,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 11
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 4,                          //index
640,                        //h264 width
480,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 12
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 5,                          //index
800,                        //h264 width
448,                        //h264 height
384,                        //local width
216,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       216,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 13
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 6,                          //index
800,                        //h264 width
600,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 14
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 7,                          //index
960,                        //h264 width
544,                        //h264 height
384,                        //local width
216,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       216,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 15
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 8,                          //index
960,                        //h264 width
720,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 16
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 9,                          //index
1280,                       //h264 width
720,                        //h264 height
384,                        //local width
216,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       216,                        //local height
5,                          //min fps
30                          //max fps

},
#if USB_UVC_1080P_MJPEG_EN
// frame desc 17
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 10,                         //index
1600,                       //h264 width
1200,                       //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate       240,                        //local height
5,                          //min fps
30                          //max fps

},
// frame desc 18
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_MJPG,     //payload format
SKYPE_MJPEG_IDX + 11,                         //index
1920,                       //h264 width
1080,                       //h264 height
384,                        //local width
216,                        //local height
100,                        //min bitrate
2500,                       //max bitrate
5,                          //min fps
30                          //max fps
},
#endif
#endif
#if SKYPE_UVC_H264 //skype 1.1
// frame desc 19
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_UVC11_H264,       //payload format
SKYPE_UVC11_H264_IDX + 0,                         //index
1280,                       //h264 width
720,                        //h264 height
320,                        //local width
180,                        //local height
100,                        //min bitrate
2500,                       //max bitrate
5,                          //min fps
30                          //max fps
},
// frame desc 20
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_UVC11_H264,       //payload format
SKYPE_UVC11_H264_IDX + 1,                         //index
640,                        //h264 width
480,                        //h264 height
320,                        //local width
240,                        //local height
100,                        //min bitrate
2500,                       //max bitrate
5,                          //min fps
30                          //max fps
},
// frame desc 21
{
sizeof(AitH264FrameDesc),   //length
PAYLOAD_FORMAT_ID_UVC11_H264,       //payload format
SKYPE_UVC11_H264_IDX + 2,                         //index
320,                        //h264 width
240,                        //h264 height
160,                        //local width
120,                        //local height
100,                        //min bitrate
500,                       //max bitrate
5,                          //min fps
30                          //max fps
},
#endif
}
};




#if SUPPORT_ISP_ENGINEERING_MODE_FUNCTION
MMP_BOOL bDownloadTabletoRAM = 0;
#endif
#define DOWNLOAD_MMP_FW_CMD    0x01
#define GET_DRAM_SIZE          0x02
#define GET_FLASH_ID           0x03
#define GET_FLASH_SIZE         0x04
#define ERASE_FLASH            0x05
#define CHECKSUM_RESULT        0x06
#define SET_MAX_QP             0x07
#define SET_MIN_QP             0x08
#define SET_P_FRAME_COUNT      0x09
#define SET_RW_DATA_PARAM      0x0A
#define SET_ENCODING_RESOLUTION 0x0B
#define SET_STREAM_LAYOUT       0x0C
#define SET_ADUIO_PLAY_MODE     0x0D
#define LED_CONTROL_MODE        0x0E
#define MJPG_SINGLE_CAPTURE     0x12
#define DEVICE_RESET            0x16
#define GPIO_CONTROL            0x14
#if (CUSTOMER == PNS)
#define SET_CROP_YUY2           0xA1
#endif
#define SENSOR_CONTROL          0x17
#define SENSOR_INUSE        0x01
#define CALI_TABLE          0x02
#define UART_CONTROL            0x18
#if SUPPORT_OSD_FUNC
#define OSD_CUSTOMER_DATA       0x20
#define TIMER_DISPLAY_CONTROL   0x21
#define SET_RTC_DATE_TIME       0x22
#define SET_RTC_DATE_TIME_FMT   0x26
#define SET_OSD_DISPLAY_COLOR   0x27
#endif
#define GET_CAMERA_INUSE        0xA0

#if (CUSTOMER == PNS)
MMP_UBYTE POP_UP_LOOP = 0,POP_Up_Cycle = 12;
extern MMP_USHORT X_Start,Y_Start;
extern MMP_UBYTE CROP_EN;
#endif
extern MMP_BOOL ubDisableUartSW;
RES_TYPE_LIST FB_s2_res = PCCAM_640_360;
void usb_vc_eu1_mmp_cmd(MMP_UBYTE *cmd)//cmd -> 8byte
{
    MMP_BOOL IsPreviewEnable;

    //dbg_printf(2, "mmp cmd x%02X x%02X x%02X x%02X x%02X\r\n", cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]);

    eu1_get_mmp_result_val[0] = XU_MMP_CMD_OK;

    switch(cmd[0]){
    case DOWNLOAD_MMP_FW_CMD:
        //FW burning,burn the firmware in task instead of ISR
        switch(cmd[1]){
        case 0:
            //USB_DownloadFWInitialize()
            gbUVCDSCCommand = XU_MMP_DOWNLOADING;//0x80;
            //MMPF_USBCTL_PostMsg(2,TASK_USB_PRIO,USBCTL_MSG_OTHERS,0,(void *)NULL);
            //Truman@120803. Originally it post msg to USB task(PRIO:4) and then to PCAM task(PRIO:29)
            //The next download FW is in SYS task.
            //if USB_DownloadFWInitialize print too much UART message. It would make download FW faster
            //and cause hanging.
#if SUPPORT_ISP_ENGINEERING_MODE_FUNCTION
            if((cmd[2] == 1) && (cmd[3] == 5 || cmd[3] == 6) && (bDownloadTabletoRAM == 0)){
                MMPF_VIF_EnableOutput(0);
                MMPF_Sensor_CheckFrameStart(1);
                bDownloadTabletoRAM = 1;
                RTNA_DBG_Str(0, "\r\nPause VIF!!\r\n");
            }
#endif
            {
                extern MMP_ERR USB_DownloadFWInitialize(void);
#if WATCHDOG_RESET_EN==1
                MMPF_WD_EnableWD(MMP_FALSE, MMP_FALSE, MMP_TRUE, NULL, MMP_TRUE);
#endif
                USB_DownloadFWInitialize();
            }
            //            MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);
            break;
        case 1:
            //possible to USB_Burning840FW2SFlash
            gbUVCDSCCommand = XU_MMP_BURNING;//0x81;
            gbUVCPara[0] = cmd[3];  // 0: old FW Package, 1: new ROM Package
#if (SUPPORT_ISP_ENGINEERING_MODE_FUNCTION==1||SUPPORT_ISP_CALIBRATION_FUNCTION==1)
            gbUVCPara[1] = cmd[2]; //1: Program RAM.  2: EEPROM. 3: Serial Flash
            gbUVCPara[2] = cmd[4]; //sensor ID, start from 0
#endif
            MMPF_USBCTL_PostMsg(2, TASK_USB_PRIO, USBCTL_MSG_OTHERS, 0, (void *) NULL);
            //            MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);
            break;
        case 0x10:
            //read flash partial
             {
                extern MMP_UBYTE *USBFirmwareBinPtr;
                extern MMP_ULONG USBFirmwareBinSize;
                MMP_ULONG FlashAddr;
                MMP_USHORT Len; // in bytes
                FlashAddr = cmd[2] + cmd[3] * 0x100 + cmd[4] * 0x10000 + cmd[5] * 0x1000000;
                Len = cmd[6] + cmd[7] * 0x100;

#if (EN_DBGLOG_FOR_FLASH)
                RTNA_DBG_Str(3, "Read flash: Addr=");
                RTNA_DBG_Long(3, FlashAddr);
                RTNA_DBG_Str(3, "Len=");
                RTNA_DBG_Short(3, Len);
                RTNA_DBG_Str(3, "\r\n");
#endif

                USBFirmwareBinPtr = (MMP_UBYTE *) (FW_DOWNLOAD_BUFFER);
                USBFirmwareBinSize = 0;
                MMPF_SF_SetTmpAddr((MMP_ULONG) SIF_BUFFER_START);
                MMPF_SF_InitialInterface();
                if(MMPF_SF_Reset()){
#if (EN_DBGLOG_FOR_FLASH)
                    RTNA_DBG_Str(0, "\r\nSIF init error !!\r\n");
#endif
                }
                MMPF_SIF_ReadDataEx(FlashAddr, (MMP_ULONG) USBFirmwareBinPtr, Len); //read flash data to buffer
#if (EN_DBGLOG_FOR_FLASH)
                RTNA_DBG_Str(3, "Data ready.\r\n");
#endif

                gDEParam.id = 2;
                gDEParam.data_len = Len;
                gDEParam.cur_offset = 0;
                gDEParam.ptr = (MMP_BYTE *) USBFirmwareBinPtr;
            }
            break;
#if SUPPORT_ISP_CALIBRATION_FUNCTION
        case 0x20:
            //Erase calibration data from flash
            dbg_printf(3, "Erase calibration data\r\n");
            USB_EraseCaliHeader();
            break;
#endif
        default:
            break;
        }
        break;
    case GET_DRAM_SIZE:
        eu1_get_mmp_result_val[1] = 0x00;  // LSB
        eu1_get_mmp_result_val[2] = 0x00;
        eu1_get_mmp_result_val[3] = 0x00;
        eu1_get_mmp_result_val[4] = 0x02;  // MSB

        break;
    case GET_FLASH_ID:
        eu1_get_mmp_result_val[1] = 0x01;  // 1: serial flash, 2: NAND flash

        //MMPF_SIF_Init();
        if(USB_ResetFlash()){
            RTNA_DBG_Str(0, "\r\nSIF init error !!\r\n");
        }

        eu1_get_mmp_result_val[2] = *(MMP_UBYTE *) (SIF_BUFFER_START);  // LSB
        eu1_get_mmp_result_val[3] = *(MMP_UBYTE *) (SIF_BUFFER_START + 1);
        eu1_get_mmp_result_val[4] = *(MMP_UBYTE *) (SIF_BUFFER_START + 2);  //
        eu1_get_mmp_result_val[5] = *(MMP_UBYTE *) (SIF_BUFFER_START + 3);  // MSB

        break;
    case GET_FLASH_SIZE:
         {
            MMP_ULONG flash_size;
            if(USB_ResetFlash()){
                RTNA_DBG_Str(0, "\r\nSIF init error !!\r\n");
            }
            flash_size = MMPF_SF_GetTotalSize();
            eu1_get_mmp_result_val[1] = flash_size & 0xFF;  // LSB
            eu1_get_mmp_result_val[2] = (flash_size >> 8) & 0xFF;
            eu1_get_mmp_result_val[3] = (flash_size >> 16) & 0xFF;
            eu1_get_mmp_result_val[4] = (flash_size >> 24) & 0xFF;  // MSB
        }
        break;
    case ERASE_FLASH:
        switch(cmd[1]){
        case 1:
            // Chip Erase
            gbUVCDSCCommand = 0x90;
            MMPF_USBCTL_PostMsg(2, TASK_USB_PRIO, USBCTL_MSG_OTHERS, 0, (void *) NULL);
            //            MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);
            break;
        case 2:
            // Sector Erase
            gbUVCDSCCommand = 0x91;
            gbUVCPara[0] = cmd[2];  // LSB
            gbUVCPara[1] = cmd[3];
            gbUVCPara[2] = cmd[4];
            gbUVCPara[3] = cmd[5];  // MSB
            MMPF_USBCTL_PostMsg(2, TASK_USB_PRIO, USBCTL_MSG_OTHERS, 0, (void *) NULL);
            //            MMPF_OS_SetFlags(SYS_Flag_Hif, SYS_FLAG_USBOP, MMPF_OS_FLAG_SET);
            break;
        default:
            break;
        }
        break;
    case CHECKSUM_RESULT:
         {
            //
            MMP_UBYTE result = 0;
            //result = GetFlashChecksumResult();
            if(result == 0) // checksum result ok
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
            else
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_FAILED;
            break;
        }
    case SET_P_FRAME_COUNT:
         {
            //MMP_ULONG PframeCount;

            //PframeCount = (MMP_ULONG)(cmd[1]);
            //PframeCount += (MMP_ULONG)(cmd[2] << 8);
            //PframeCount += (MMP_ULONG)(cmd[3] << 16);
            //PframeCount += (MMP_ULONG)(cmd[4] << 24);

            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if(IsPreviewEnable){
                MMPF_VIDENC_GOP_CTL GopCtl;

                if((cmd[1] + (cmd[2] << 8)) > 1024){
                    //GOP:3~1024
                    cmd[1] = 0x00;
                    cmd[2] = 0x04;
                }
                if((cmd[1] + (cmd[2] << 8)) < 3){
                    //GOP:3~1024
                    cmd[1] = 0x03;
                    cmd[2] = 0x00;
                }
                GopCtl.usGopSize = cmd[1] + (cmd[2] << 8);
                GopCtl.usMaxContBFrameNum = 0;
                if(XU_Ctrl_StreamID == 0)
                    MMPF_VIDENC_SetParameter(0, MMPF_VIDENC_ATTRIBUTE_GOP_CTL, (void *) &GopCtl);
                else if(XU_Ctrl_StreamID == 1)
                    MMPF_VIDENC_SetParameter(1, MMPF_VIDENC_ATTRIBUTE_GOP_CTL, (void *) &GopCtl);
                else if(XU_Ctrl_StreamID == 0xFF){
                    MMPF_VIDENC_SetParameter(0, MMPF_VIDENC_ATTRIBUTE_GOP_CTL, (void *) &GopCtl);
                    MMPF_VIDENC_SetParameter(1, MMPF_VIDENC_ATTRIBUTE_GOP_CTL, (void *) &GopCtl);
                }
                dbg_printf(3, "H:%X GOP Size : %d\r\n", XU_Ctrl_StreamID, GopCtl.usGopSize);
            }
            else{
                //gsCurH264Config.wIFramePeriod = (MMP_USHORT)(PframeCount * 10 / gsVideoEncodeFPS);

                //RTNA_DBG_Str(3,"wIFramePeriod = ");
                //RTNA_DBG_Long(3,gsCurH264Config.wIFramePeriod);
                //RTNA_DBG_Str(3,"\r\n");
            }

            break;
        }
    case SET_RW_DATA_PARAM:
         {
            switch(cmd[1]){
            case 1:
                //read resolution list
                gDEParam.id = 1;
                gDEParam.data_len = H264FormatList.Length;
                gDEParam.cur_offset = 0;
                gDEParam.ptr = (MMP_BYTE *) &H264FormatList;
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
                RTNA_DBG_Str(0, "SET_RW_DATA_PARAM set current.\r\n");
                break;
            default:
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_FAILED;
                break;
            }
            break;
        }
    case SET_ENCODING_RESOLUTION:
         {
#if USB_FRAMEBASE_H264_MJPEG_STREAM || USB_FRAMEBASE_DUAL_H264_STREAM
            //0x88:H264+MJPEG mode  0x86:H264+H264 mode
            if((gbSkypeMode == FRAMEBASE_H264RT_MJPEG) || (gbSkypeMode == FRAMEBASE_DUAL_H264) ||
               (gbSkypeMode == FRAMEBASE_DUAL_H264_MJPEG) || (gbSkypeMode == FRAMEBASE_H264FRAME_MJPEG)){
                MMP_BOOL IsPreviewEnable;
                MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
                if(cmd[1] == 1)
                    FB_s2_res = PCCAM_160_120;
                else if(cmd[1] == 2)
                    FB_s2_res = PCCAM_320_240;
                else if(cmd[1] == 3)
                    FB_s2_res = PCCAM_640_480;
                else if(cmd[1] == 18)
                    FB_s2_res = PCCAM_160_90;
                else if(cmd[1] == 19)
                    FB_s2_res = PCCAM_320_180;
                else if(cmd[1] == 13)
                    FB_s2_res = PCCAM_640_360;
                else if(cmd[1] == 23)
                    FB_s2_res = PCCAM_480_270;
                
                if((gbSkypeMode == FRAMEBASE_H264RT_MJPEG) && IsPreviewEnable)
                    ChangeMJEEG_PreviewResolution(FB_s2_res, 0);
                if((gbSkypeMode == FRAMEBASE_DUAL_H264_MJPEG) && IsPreviewEnable)
                    ChangeMJEEG_SnapshotResolution(FB_s2_res, 0);
            } else
#endif
            {
                gbSkypeEncRes = cmd[1];

                RTNA_DBG_Str(0, "gbSkypeEncRes = ");
                RTNA_DBG_Byte(0, gbSkypeEncRes);
                RTNA_DBG_Str(0, "\r\n");
            }
            break;
        }
    case SET_STREAM_LAYOUT:
         {
            gbSkypeMode = cmd[1];

            RTNA_DBG_Str(0, "gbSkypeMode = ");
            RTNA_DBG_Short(0, gbSkypeMode);
            RTNA_DBG_Str(0, "\r\n");

            break;
        }
    case LED_CONTROL_MODE:
         {
            if(cmd[2] == ON){
                //USB_LEDDisplay(LED_READY, LED_ON);
            }
            else{
                //USB_LEDDisplay(LED_READY, LED_OFF);
            }

#if SUPPORT_FLASH_LIGHT

            if(cmd[2] == ON){
#if (CUSTOMER == LON) || ((CUSTOMER == CCN)&&(MODEL == 2))
                GPIO_OutputControl(CAM_EN, TRUE);
                MMPF_OS_Sleep(1);
#endif

                VR_Flash_Init();

                VR_Flash_SetMode(ISP_FLASH_MODE_VIDEO_FORCE_ON);
                VR_Flash_Ctl(ISP_FLASH_CTL_EN, ISP_FLASH_TYPE_VIDEO);
            }
            else{
                VR_Flash_Ctl(ISP_FLASH_CTL_DIS, ISP_FLASH_TYPE_VIDEO);

#if (CUSTOMER == LON) || ((CUSTOMER == CCN)&&(MODEL == 2))
                GPIO_OutputControl(CAM_EN, FALSE);
#endif
            }
#endif

            RTNA_DBG_Str(0, "LED type = ");
            RTNA_DBG_Short(0, cmd[1]);
            RTNA_DBG_Str(0, ",  value = ");
            RTNA_DBG_Short(0, cmd[2]);
            RTNA_DBG_Str(0, "\r\n");

            break;
        }
    case UART_CONTROL:
         {
            ubDisableUartSW = (MMP_BOOL) cmd[2];
            eu1_get_mmp_result_val[1] = ubDisableUartSW;
        }
        break;
#if SUPPORT_OSD_FUNC
    case OSD_CUSTOMER_DATA:
        {
            //cmd[1]    String Addr Number
            //cmd[2]    String ASCII data
            //cmd[3]    String Clear all   0:Default 1:Clear
            MMP_UBYTE i = 0;
            if(cmd[3]) {
                for(i=0;i<32;i++)   //array max is 32
                    strCustomerData[i] = NULL;
            }
            else {
                for(i=0;i<cmd[1];i++) {
                    if(strCustomerData[i] == NULL) {
                        eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                        eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                        dbg_printf(3,"Not sequence enter!!!\r\n");
                        return;
                    }
                }
                if(cmd[1]>31) {
                    eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    dbg_printf(3,"Over support lenght!!!\r\n");
                    return;
                }
                if((cmd[2]<0x20)||(cmd[2]>0x7E)) {
                    eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    dbg_printf(3,"Over support string!!!\r\n");
                    return;
                }
                strCustomerData[cmd[1]] = cmd[2];
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
                eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_OK;
            }
        }
        break;
    case TIMER_DISPLAY_CONTROL:
         {
            //cmd[1]    Enable/Disable display timer
            //cmd[2]    Offset X Low Byte
            //cmd[3]    Offset X High Byte
            //cmd[4]    Offset Y Low Byte
            //cmd[5]    Offset Y High Byte
            extern MMP_BOOL gbOSDDisplayEn;
            extern MMP_USHORT m_usOsdStartXOffset, m_usOsdStartYoffset;
            MMP_UBYTE i = 0;
            if(cmd[1] == 1){
                gbOSDDisplayEn = 1;
                m_usOsdStartXOffset = cmd[3] << 8 | cmd[2];
                m_usOsdStartYoffset = cmd[5] << 8 | cmd[4];
                dbg_printf(3, "Enable display timer\r\n");
                dbg_printf(3, "Offset X:%d  Y:%d\r\n", m_usOsdStartXOffset, m_usOsdStartYoffset);
            }
            else if(cmd[1] == 2){  // clear customer data/disable cutomer data display
                bEnableSetData32Transfer = 0;
                for(i=0;i<32;i++)   //array max is 32
                    strCustomerData[i] = NULL;
            }
            else if(cmd[1] == 3){  // set customer data via EU1_SET_DATA_32 command
                bEnableSetData32Transfer = 1;
                m_usOsdStartXOffset = cmd[3] << 8 | cmd[2];
                m_usOsdStartYoffset = cmd[5] << 8 | cmd[4];
            }
            else{
                gbOSDDisplayEn = 0;
                dbg_printf(3, "Disable display timer\r\n");
            }
        }
        break;
    case SET_RTC_DATE_TIME:
         {
            //Bruce add 20130604
            //[2:1] year, [3] month, [4] day, [5] hour, [6] minute, [7] second
            if((cmd[3] < 1) ||
               (cmd[3] > 12) ||
               (cmd[4] < 1) ||
               (cmd[4] > 31) ||
               (cmd[5] > 23) ||
               (cmd[6] > 59) ||
               (cmd[7] > 59)){
                dbg_printf(1, "Error Param!\r\n");
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
            }
            else{
                pcam_SetClock(((MMP_USHORT) cmd[2] << 8 | cmd[1]), cmd[3], cmd[4], cmd[5], cmd[6], cmd[7]);
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
                eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_OK;
                eu1_get_mmp_cmd16_result_val[1] = cmd[1];
                eu1_get_mmp_cmd16_result_val[2] = cmd[2];
                eu1_get_mmp_cmd16_result_val[3] = cmd[3];
                eu1_get_mmp_cmd16_result_val[4] = cmd[4];
                eu1_get_mmp_cmd16_result_val[5] = cmd[5];
                eu1_get_mmp_cmd16_result_val[6] = cmd[6];
                eu1_get_mmp_cmd16_result_val[7] = cmd[7];
            }
            break;
        }
    case SET_RTC_DATE_TIME_FMT:
        {
            //cmd[1]:DateFmt 1.%Y-%M-%D  2.%M/%D/%Y  4.%D/%M/%Y
            //cmd[2]:TimeFmt 1.24Hour,%H:%M:%S  2.12Hour,%I:%M:%S%P
            #include "pCam_osd_api.h"
            extern MMP_UBYTE ubOSDDateFmt, ubOSDTimeFmt;
            extern MMP_UBYTE gbOSDTimeFormatChange;
            switch(cmd[1])
            {
            #if (CUSTOMER == ANW)
                case 0:
                    ubOSDDateFmt = PCAM_ACC_TIMESTAMP_FORMAT_1;  // Y-M-D
                    break;
            #endif
                case 1:
                    ubOSDDateFmt = PCAM_ACC_TIMESTAMP_FORMAT_2;  // Y/M/D
                    break;
                case 2:
                    ubOSDDateFmt = PCAM_ACC_TIMESTAMP_FORMAT_4;  // M/D/Y
                    break;
                case 4:
                    ubOSDDateFmt = PCAM_ACC_TIMESTAMP_FORMAT_3;  // D/M/Y
                    break;
                default:
                    eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    break;
            }
            switch(cmd[2])
            {
                case 1:
                    ubOSDTimeFmt = 0;   //24Hour
                    gbOSDTimeFormatChange = 1;
                    break;
                case 2:
                    ubOSDTimeFmt = 1;   //12Hour
                    gbOSDTimeFormatChange = 1;
                    break;
                default:
                    eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    break;
            }
        }
        break;
    case SET_OSD_DISPLAY_COLOR:
        {
#if (MOVE_OSD_USING_DMA)
            MMP_ULONG i;
            MMP_USHORT *UVptr;
#endif
            MMP_UBYTE  R, G, B;

            R = cmd[2];              
            G = cmd[3];              
            B = cmd[4]; 
            pcam_Osd_TranslateRGB2YUV(R, G, B, &gbOSDForeColorY, &gsOSDForeColorUV);
                         
            
            R = cmd[5];              
            G = cmd[6];              
            B = cmd[7];              
            pcam_Osd_TranslateRGB2YUV(R, G, B, &gbOSDBackColorY, &gsOSDBackColorUV);

#if (MOVE_OSD_USING_DMA)
            MEMSET((void*)glOSDBufferYAddr[0], gbOSDBackColorY, glOSDBufferYSize[0]);

            UVptr = (MMP_USHORT *)(glOSDBufferUVAddr[0]);
            for(i = 0 ; i < glOSDBufferUVSize[0]/2 ; i++){
                *(UVptr + i) = gsOSDBackColorUV;
            } 

            MEMSET((void*)glOSDBufferYAddr[1], gbOSDBackColorY, glOSDBufferYSize[1]);

            UVptr = (MMP_USHORT *)(glOSDBufferUVAddr[1]);
            for(i = 0 ; i < glOSDBufferUVSize[1]/2 ; i++){
                *(UVptr + i) = gsOSDBackColorUV;
            } 
#endif
            
            break;
        }
#endif
#if XU_FRAMEBASE_CAPTURE
#if (CHIP_AIT8451==1) && (!BIND_SENSOR_AR0832E)
    case MJPG_SINGLE_CAPTURE:
        {
            //cmd[1]    //0x01:Capture format is JPEG
            //cmd[2]    //Capture of number
            //cmd[3]	//LowByte Resolution
            //cmd[4]	//HighByte Resolution
            //cmd[5]	//Quality
            extern MMP_UBYTE gbGraphicLoopBackSource, gbGraLBEvent;
            extern MMP_ULONG Cap_W, Cap_H, Cap_jpeg;
            RES_TYPE_CFG* CapCfg;
            RES_TYPE_LIST MappingRes[7] = {PCCAM_1280_720, PCCAM_640_480, PCCAM_640_360, PCCAM_320_240,
                                           PCCAM_320_180, PCCAM_160_120, PCCAM_160_90};
            MMP_BOOL IsPreviewEnable;
            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if((IsPreviewEnable==MMP_TRUE) && cmd[1]) {
                dbg_printf(3,"== JPEG Capture ==\r\n");
                gFramebaseCap.CapResol = FB_s2_res;
                gFramebaseCap.orgMJPG_Quality = Q_Level;
                Q_Level = cmd[5];
                if(Cap_jpeg) {
                    dbg_printf(3,"Cap busy[%d]\r\n",Cap_jpeg);
                    return;
                }

                FB_s2_res = MappingRes[7 - cmd[3]];

                CapCfg = GetResCfg(FB_s2_res);
                Cap_W = CapCfg->res_w;
                Cap_H = CapCfg->res_h;

                if((FB_s2_res==gFramebaseCap.CapResol)&&(gbSkypeMode!=0x86)) {//Capture dump
                    gFramebaseCap.JPEG = cmd[1];
                    Q_Level = gFramebaseCap.orgMJPG_Quality;
                    dbg_printf(3,"JPEG Capture Dump!!!\r\n");
                    break;
                }
                if(gbSkypeMode==0x86)
                    gbGraLBEvent = 1;

                gbGraphicLoopBackSource = PIPE_0;
                Cap_jpeg = 1;
            }
        }
        break;
#elif (CHIP_AIT8451==0) || BIND_SENSOR_AR0832E
    case MJPG_SINGLE_CAPTURE:  //Test capture Method 1
        {
            //cmd[1]    //0x01:Capture format is JPEG
            //cmd[2]    //Capture of number
            //cmd[3]	//LowByte Resolution
            //cmd[4]	//HighByte Resolution
            //cmd[5]	//Quality
            extern MMP_ULONG Cap_W, Cap_H, Cap_jpeg;
            RES_TYPE_CFG* CapCfg;
            #if BIND_SENSOR_AR0832E
            RES_TYPE_LIST MappingRes[6] = {PCCAM_640_480, PCCAM_1280_720, PCCAM_1280_960,
                                           PCCAM_1920_1080, PCCAM_2048_1536, PCCAM_2592_1944};
            #else
            RES_TYPE_LIST MappingRes[7] = {PCCAM_1280_720, PCCAM_640_480, PCCAM_640_360, PCCAM_320_240,
                                           PCCAM_320_180, PCCAM_160_120, PCCAM_160_90};
            #endif
            MMP_BOOL IsPreviewEnable;
            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if((IsPreviewEnable==MMP_TRUE) && cmd[1]) {
                dbg_printf(3,"JPEG Capture Start!!!\r\n");
                #if BIND_SENSOR_AR0832E
                if((cmd[3]<1) || (cmd[3]>6)) {
                    eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    return;
                }
                FB_s2_res = glPccamResolution;
                #endif
                gFramebaseCap.CapResol = FB_s2_res;
                gFramebaseCap.orgMJPG_Quality = Q_Level;
                Q_Level = cmd[5];
                #if BIND_SENSOR_AR0832E
                FB_s2_res = MappingRes[cmd[3]-1];
                #else
                FB_s2_res = MappingRes[7 - cmd[3]];
                #endif

                CapCfg = GetResCfg(FB_s2_res);
                Cap_W = CapCfg->res_w;
                Cap_H = CapCfg->res_h;

                if(FB_s2_res == gFramebaseCap.CapResol) {//Capture dump
                    gFramebaseCap.JPEG = cmd[1];
                    Q_Level = gFramebaseCap.orgMJPG_Quality;
                    dbg_printf(3,"JPEG Capture Dump!!!\r\n");
                    break;
                }

                Cap_jpeg = 2;
                ChangeMJEEG_PreviewResolution(FB_s2_res, 1);//Capture
                Cap_jpeg = 0;

                /* A <-> B */
                FB_s2_res = gFramebaseCap.CapResol + FB_s2_res;
                gFramebaseCap.CapResol = FB_s2_res - gFramebaseCap.CapResol;
                FB_s2_res = FB_s2_res - gFramebaseCap.CapResol;
                /* A <-> B */
                Q_Level = gFramebaseCap.orgMJPG_Quality + Q_Level;
                gFramebaseCap.orgMJPG_Quality = Q_Level - gFramebaseCap.orgMJPG_Quality;
                ChangeMJEEG_PreviewResolution(FB_s2_res, 0);//Loopback

                dbg_printf(3,"JPEG Capture End!!!\r\n");
            }
        }
        break;
#else
    case MJPG_SINGLE_CAPTURE:
        {
            //cmd[1]    //0x01:Capture format is JPEG
            //cmd[2]    //Capture of number
            //cmd[3]	//LowByte Resolution
            //cmd[4]	//HighByte Resolution
            //cmd[5]	//Quality
            extern MMP_UBYTE gbStillCaptureEvent;
            extern MMP_ULONG Capture_Time;
            MMP_BOOL IsPreviewEnable;
            #if (CUSTOMER == PNS)
            extern MMP_BOOL Disable_Capture;
            Disable_Capture = 0;
            #endif
            Capture_Time=MMPF_BSP_GetTick();
            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);

            if((IsPreviewEnable==MMP_TRUE)&&(gbStillCaptureEvent==STILL_IMAGE_WAITING)) {
                gFramebaseCap.JPEG = cmd[1];
                gFramebaseCap.CapResol = cmd[3];
                gFramebaseCap.orgMJPG_Quality = Q_Level;
                Q_Level = cmd[5];
                gFramebaseCap.orgFramerate = ISP_IF_AE_GetFPS();
                dbg_printf(3,"## MJPEG single capture\r\n");	//Continuous second capture issus by JengWei

                gbStillCaptureEvent = STILL_IMAGE_TRIGGER;
                MMPF_USBCTL_PostMsg(2,TASK_USB_PRIO,USBCTL_MSG_OTHERS,0,(void *)NULL);
            }
            else{
                dbg_printf(3,"Skip the capture\r\n");
            }
        }
        break;
#endif  //#if CHIP_AIT8451
#endif
#if (CUSTOMER == PNS)
    case GPIO_CONTROL:
         {
            AITPS_GPIO  pGPIO = AITC_BASE_GPIO;
            if(cmd[3] == 2){
                //POP-UP
                void PNS_SOLENOID_CTRL(void);
                PNS_SOLENOID_CTRL();
            }
            else if(cmd[3] == 3){
                //Start POP-UP loop(1/10s)
                POP_UP_LOOP = 1;
            }
            else if(cmd[3] == 4){
                //Stop POP-UP loop
                POP_UP_LOOP = 0;
            }
            else if(cmd[3] == 5){
                //Test Watch Dog function
                while(1){
                };
            }
            else{
                if(cmd[1] == 1){
                    //read
                    eu1_get_mmp_result_val[1] = ((pGPIO->GPIO_DATA[0] & (1 << cmd[2])) ? 1 : 0);//gpio value
                }
                else if(cmd[1] == 0){
                    //write
                    GPIO_OutputControl(cmd[2], cmd[3]);
                }
            }
        }
        break;
    case SET_CROP_YUY2:
        //Crop YUY2 function
         {
            if(cmd[2]){
                CROP_EN = 1;
                dbg_printf(3, "CropEnable X:x%X Y:x%X\r\n", X_Start, Y_Start);
            }
            else{
                CROP_EN = 2;
                dbg_printf(3, "CropDisable!!!\r\n");
            }
            X_Start = (cmd[3] << 8) + cmd[4];
            Y_Start = (cmd[5] << 8) + cmd[6];
        }
        break;
#else
    case GPIO_CONTROL:
         {
            AITPS_GPIO  pGPIO = AITC_BASE_GPIO;
            if(cmd[1] == 1){
                //read
                eu1_get_mmp_result_val[1] = ((pGPIO->GPIO_DATA[0] & (1 << cmd[2])) ? 1 : 0);//gpio value
            }
            else if(cmd[1] == 0){
                //write
                GPIO_OutputControl(cmd[2], cmd[3]);
            }
        }
        break;
#endif
    case DEVICE_RESET:
        //cmd[1]: 0: Rom boot    1: UVC mode
        switch(cmd[1]) {
        case 0:
            usb_ep0_null_in();
            MMPF_SYS_SelfRomBoot();
            break;
        case 1:
            #if (CHIP_VER == VER_B) // reset AIT to reboot ROM           
            MMPF_SYS_ResetSystem(0x0);
            #endif
            break;
        }
        break;
    case SENSOR_CONTROL:
        switch(cmd[2]){
        case SENSOR_INUSE:
#if SUPPORT_SWITCH_CAMERA
            if(GET_CUR_CMD == cmd[1]){
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
                eu1_get_mmp_result_val[1] = gbSwitchSensor;
            }
            else if((SET_CUR_CMD == cmd[1]) && (cmd[3] < TOTAL_SENSOR_NUMBER)){
                //set current sensor
                if((gbSwitchSensor != cmd[3])){
                    //need to switch
                    gbSwitchSensor = cmd[3];
                    gbTestCaliTable = CALI_TABLE_UNDEFINED;

                    MMPF_Sensor_Set3AState(MMPF_SENSOR_3A_RESET);//sensor change! for gsSensorFunction->MMPF_Sensor_InitializeISP()==>ISP_IF_LIB_Init()
                    MMPF_Sensor_SetBufferSize(0);

                    //dbg_printf(0,"1.disconnect, ");
                    usb_sw_enum();
                    //dbg_printf(0,"2.re-connect!");
                }
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
                eu1_get_mmp_result_val[1] = gbSwitchSensor;
            }
            else{
                dbg_printf(1, "  SENSOR_INUSE param error\r\n");
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OUT_OF_RANGE;
            }
#else
            dbg_printf(1, "  Function-less!(SUPPORT_SWITCH_CAMERA=0)\r\n");
            eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
#endif//SUPPORT_SWITCH_CAMERA
            break;
#if SUPPORT_ISP_CALIBRATION_FUNCTION
        case CALI_TABLE:
            //MMPS_3GPRECD_GetPreviewDisplay
            if(GET_CUR_CMD == cmd[1]){
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
                eu1_get_mmp_result_val[1] = gbTableUsed;//return current setting. irrelevant to sensor ID
            }
            else if((SET_CUR_CMD == cmd[1]) && (cmd[3] < TOTAL_SENSOR_NUMBER)){
                //well, ignore sensor setting for now
                gbTableUsed = cmd[4];
                //reset
                MMPF_Sensor_Set3AState(MMPF_SENSOR_3A_RESET);//sensor change! for gsSensorFunction->MMPF_Sensor_InitializeISP()==>ISP_IF_LIB_Init()
                MMPF_Sensor_SetBufferSize(0);
            }
#else
            dbg_printf(1, "  Function-less!(SUPPORT_SWITCH_CAMERA=0)\r\n");
            eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
#endif //SUPPORT_ISP_CALIBRATION_FUNCTION
            break;
        default:
            eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
            break;
        }
        break;
    case GET_CAMERA_INUSE:
         {
            if((cmd[0] == GET_CAMERA_INUSE) && (cmd[1] == GET_CUR_CMD)){
                MMP_UBYTE bIsCurrentResolution5M;

                switch(gbCurFormatIndex){
                #if ENABLE_YUY2
                case YUY2_FORMAT_INDEX:
                    bIsCurrentResolution5M = (yuy2_frame_index_to_pcam(gbCurFrameIndex) == PCCAM_2592_1944) ? 1 : 0;
                    break;
                #endif
                #if ENABLE_MJPEG
                case MJPEG_FORMAT_INDEX:
                    bIsCurrentResolution5M = (mjpg_frame_index_to_pcam(gbCurFrameIndex) == PCCAM_2592_1944) ? 1 : 0;
                    break;
                #endif
                default:
                    bIsCurrentResolution5M = 0;
                }

#if SUPPORT_SWITCH_CAMERA
                eu1_get_mmp_result_val[1] = ((m_bVidRecdPreviewStatus == MMP_TRUE) &&
                                             (gbSwitchSensor == 1) &&
                                             (bIsCurrentResolution5M));//5M preview
#else
                eu1_get_mmp_result_val[1] = ((m_bVidRecdPreviewStatus == MMP_TRUE) &&
                                             (gbCurrentSensor == 1) &&
                                             (bIsCurrentResolution5M));//5M preview
#endif
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
            }
            else{
                dbg_printf(1, "  CMD NOT SUPPORT!\r\n");
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
            }
        }
        break;
    case 0xFF:
        // USB XU external I2C command
         {
            switch(cmd[1]){
            case 0:
                //set I2C slave address
                //cmd[2] = slave address
                gsUSBXU_I2C_ID = cmd[2];
                RTNA_DBG_Str(0, "XU_I2C_ID =");
                RTNA_DBG_Byte(0,gsUSBXU_I2C_ID);
                RTNA_DBG_Str(0, "\r\n");
                break;

            case 1:
                //write I2C 2A1D
                //cmd[2] = addr HB
                //cmd[3] = addr LB
                //cmd[4] = value
                USB_WriteI2C((MMP_USHORT) (cmd[2] * 256 + cmd[3]), (MMP_USHORT) cmd[4], I2C_MODE_2A1D);

                RTNA_DBG_Str(0, "[W]Reg[");
                RTNA_DBG_Short(0,(cmd[2] * 256 + cmd[3]));
                RTNA_DBG_Str(0, " ] =");
                RTNA_DBG_Byte(0,cmd[4]);
                RTNA_DBG_Str(0, "\r\n");

                break;

            case 2:
                //read I2C 2A1D
                //cmd[2] = addr HB
                //cmd[3] = addr LB
                //cmd[4] = value
                eu1_get_mmp_result_val[2] = (MMP_UBYTE) USB_ReadI2C((MMP_USHORT) (cmd[2] * 256 + cmd[3]), I2C_MODE_2A1D);

                RTNA_DBG_Str(0, "[R]Reg[");
                RTNA_DBG_Short(0,(cmd[2] * 256 + cmd[3]));
                RTNA_DBG_Str(0, " ] =");
                RTNA_DBG_Byte(0,eu1_get_mmp_result_val[2]);
                RTNA_DBG_Str(0, "\r\n");

                break;

            case 3:
                //write I2C 1A1D
                //cmd[2] = addr HB
                //cmd[3] = addr LB
                //cmd[4] = value
                USB_WriteI2C((MMP_USHORT) (cmd[2]), (MMP_USHORT) cmd[4], I2C_MODE_1A1D);

                RTNA_DBG_Str(0, "[W]Reg[");
                RTNA_DBG_Byte(0,cmd[2]);
                RTNA_DBG_Str(0, " ] =");
                RTNA_DBG_Byte(0,cmd[4]);
                RTNA_DBG_Str(0, "\r\n");

                break;

            case 4:
                //read I2C
                //cmd[2] = addr HB
                //cmd[3] = addr LB
                //cmd[4] = value
                eu1_get_mmp_result_val[2] = (MMP_UBYTE) USB_ReadI2C((MMP_USHORT) cmd[2], I2C_MODE_1A1D);

                RTNA_DBG_Str(0, "[R]Reg[");
                RTNA_DBG_Byte(0,cmd[2]);
                RTNA_DBG_Str(0, " ] =");
                RTNA_DBG_Byte(0,eu1_get_mmp_result_val[2]);
                RTNA_DBG_Str(0, "\r\n");

                break;
#if (CUSTOMER == QDR)
            case 5:
                //Get sensor chip ID
                //cmd[2] = 0x00:no error   0x80:error
                //cmd[3~7] = Return sensor name(ASCII)
#if BIND_SENSOR_AR0330 || BIND_SENSOR_AR0832E
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_OK;
#else
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
#endif
#if BIND_SENSOR_AR0330
                eu1_get_mmp_result_val[1] = 'A';
                eu1_get_mmp_result_val[2] = 'R';
                eu1_get_mmp_result_val[3] = '0';
                eu1_get_mmp_result_val[4] = '3';
                eu1_get_mmp_result_val[5] = '3';
                eu1_get_mmp_result_val[6] = '0';
                RTNA_DBG_Str(0, "Sensor name is Aptina0330CS.");
                RTNA_DBG_Str(0, "\r\n");
#elif BIND_SENSOR_AR0832E
                eu1_get_mmp_result_val[1] = 'A';
                eu1_get_mmp_result_val[2] = 'R';
                eu1_get_mmp_result_val[3] = '0';
                eu1_get_mmp_result_val[4] = '8';
                eu1_get_mmp_result_val[5] = '3';
                eu1_get_mmp_result_val[6] = '2';
                eu1_get_mmp_result_val[7] = 'E';
                RTNA_DBG_Str(0, "Sensor name is Aptina0832E.");
                RTNA_DBG_Str(0, "\r\n");
#else
                RTNA_DBG_Str(0, "Not support the sensor!!!");
                RTNA_DBG_Str(0, "\r\n");
#endif

                break;
#endif
            }
        }
        break;
    default:
        eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
        break;
    }
}
#if (CUSTOMER == ANW)
#include "mmpf_i2cm.h"
#endif
#if SUPPORT_PWM
#include "mmpf_pwm.h"
#endif
#if SUPPORT_AIT845x_MD
#include "md.h"
MMP_UBYTE MD_x_div = 10, MD_y_div = 10, MD_sensitivity = 90;
MMP_USHORT MD_Number = 0;
MMP_ULONG MD_address = 0, MD_sensitivity_number[16*12+1] = {0}, MD_sensitivity_data[16*12] = {0};
#endif
#if (CUSTOMER == ANW)&&SUPPORT_AIT845x_MD
MMP_USHORT MD_x_res = 320, MD_y_res = 200, MD_Block[25] = {0}, MD_BlockTmp[25] = {0};
MMP_BOOL ChangeMDprs = 0, ChangeMDEn = 0;
#else
MMP_USHORT MD_x_res = 320, MD_y_res = 180;
#endif
void usb_vc_eu1_mmp_cmd16(MMP_UBYTE *cmd)//cmd -> 8byte
{
#if (CUSTOMER == PNS) && SUPPORT_UAC
    extern MMP_BOOL GTKLIB_EN;
    extern MMPC_AudioExtCodec_SetMute(MMP_BOOL bMute);
    extern MMPC_AudioExtCodec_SetRecordVolume(MMP_LONG value);
#endif
#if 0
   RTNA_DBG_Str(0, "mmp cmd 16");
   RTNA_DBG_Byte(0, cmd[0]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Byte(0, cmd[1]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Byte(0, cmd[2]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Byte(0, cmd[3]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Byte(0, cmd[4]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Byte(0, cmd[5]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Byte(0, cmd[6]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Byte(0, cmd[7]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Byte(0, cmd[8]);
   RTNA_DBG_Str(0, " ");
   RTNA_DBG_Str(0, "\r\n");
#endif
    switch(cmd[0]){
    case 0x01:
        {
            MMP_SYS_PowerSaving(MMP_TRUE);
        }
        break;
    case 0x02:
        {
            MMP_SYS_PowerSaving(MMP_FALSE);
        }
        break;
    case 0x03:
        break;
    case 0x04:
        {
        }
        break;
    case 0x05:
        //Audio Mode
         {
            // CXNT_Initial_Success = 0;
            //USB_SetAudioMode(PCAM_API, cmd[1]);
        }
        break;
    case 0x06:
        //M2TS option
         {
        #if (SUPPORT_MTS || SUPPORT_MP4)
            switch(cmd[1]){
            #if (SUPPORT_MTS)                
            case 0:
                //disable m2ts
                MMPF_VIDMGR_SetMtsMuxModeEnable(MMP_FALSE);
                RTNA_DBG_Str(0, "Disable M2TS\r\n");
                break;
            case 1:
                //enable m2ts
                MMPF_VIDMGR_SetMtsMuxModeEnable(MMP_TRUE);
                RTNA_DBG_Str(0, "Enable M2TS\r\n");
                break;
            #endif                
            case 2: //start record mts
                //MMPF_VIDMGR_StartMtsRecord(0); //20130520//TBD
                USB_ForceH264IDRFrame();
                break;
            #if (SUPPORT_MP4)
            case 0x80: //disable MP4.
                MMPF_VIDMGR_SetMP4Enable(0);
                RTNA_DBG_Str(0, "Disable MP4 mode.\r\n");
            break;
            case 0x81:	//enable MP4.
                MMPF_VIDMGR_SetMP4Enable(1);
                RTNA_DBG_Str(0, "Enable MP4 mode.\r\n");
            break;
            #endif                
            }
        #endif
        }
        break;
    case 0x08:
        //JPEG Quality ,
        break;
#if SUPPORT_PWM
    case 0x0A:  //MMP16_SET_PWM_CONTROL:
        {
            MMP_ULONG nFreq;

            //[1] enable/disable, [4:2] frequency, [5] duty cycle 
            nFreq = ((MMP_ULONG)cmd[2])|((MMP_ULONG)cmd[3]<<8)|((MMP_ULONG)cmd[4]<<16);

            if((nFreq>PWM_FREQ_MAX)||(nFreq<PWM_FREQ_MIN)||(cmd[5]>PWM_DUTY_MAX)||/*(cmd[5]<PWM_DUTY_MIN)||*/
                /*(cmd[1]<PWM_CTL_DISABLE)||*/(cmd[1]>PWM_CTL_AUTO_MODE)){
                dbg_printf(1,"Error Param! CTL %d, %dHz, %d%%\r\n", cmd[1],nFreq,cmd[5]);
                eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
            }
            else{
                switch(cmd[1]) {
                case PWM_CTL_DISABLE:
                    MMPF_PWM_SetPWMAutoMode(MMP_FALSE);
                    MMPF_PWM_SetEnableControl(cmd[1]);
                    MMPF_PWM_SettingControl(nFreq, cmd[5]);
                    //dbg_printf(3," PWM:DISABLE,F_%d D_%d\r\n",nFreq,cmd[5]);
                    break;
                case PWM_CTL_ENABLE:
                    MMPF_PWM_SetPWMAutoMode(MMP_FALSE);
                    MMPF_PWM_SettingControl(nFreq, cmd[5]);
                    MMPF_PWM_SetEnableControl(cmd[1]);
                    //dbg_printf(3," PWM:ENABLE,F_%d D_%d\r\n",nFreq,cmd[5]);
                    break;
                case PWM_CTL_AUTO_MODE:
                default:
                    MMPF_PWM_SettingControl(nFreq, cmd[5]);
                    MMPF_PWM_SetEnableControl(cmd[1]);
                    MMPF_PWM_SetPWMAutoMode(MMP_TRUE);
                    //dbg_printf(3," PWM:AUTO,F_%d D_%d\r\n",nFreq,cmd[5]);
                    break;
                }
                eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_OK;
                eu1_get_mmp_cmd16_result_val[1] = cmd[1];
                eu1_get_mmp_cmd16_result_val[2] = cmd[2];
                eu1_get_mmp_cmd16_result_val[3] = cmd[3];
                eu1_get_mmp_cmd16_result_val[4] = cmd[4];
                eu1_get_mmp_cmd16_result_val[5] = cmd[5];
                eu1_get_mmp_cmd16_result_val[6] = cmd[6];
                eu1_get_mmp_cmd16_result_val[7] = cmd[7];
            }
        }
        break;
#endif
#if (CUSTOMER == PNS)
    case 0x10:
        //Audio function
        switch(cmd[1]){
#if defined(BUILD_LIB) //for Goertek audio only
        case 0x00:
            //Audio Noise Reduction mode
            NoiseReduction_mode(cmd[2]);
            break;
        case 0x01:
            //Adjust Audio Noise Reduction mode
            Adjust_NoiseReduction_parameter(cmd[2]);
            break;
        case 0x02:
            //Audio Dereverberation mode
            Dereverberation_mode(cmd[2]);
            break;
        case 0x03:
            //Adjust Audio Dereverberation mode
            Adjust_Dereverberation_parameter(cmd[2]);
            break;
#endif
#if (SUPPORT_UAC)
        case 0x10:
            //Adjust Audio Mute
            MMPC_AudioExtCodec_SetMute(cmd[2]);
            break;
        case 0x11:
            //Adjust Audio Volume
            if(cmd[2]){
                MMPC_AudioExtCodec_SetMute(0);
                MMPC_AudioExtCodec_SetRecordVolume(cmd[2]);
            }
            else
                MMPC_AudioExtCodec_SetMute(1);
            break;
#endif
        default:
            eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
            break;
        }
        break;
    case 0x11:
        //Misc function
        POP_UP_LOOP = cmd[1];
        if(POP_UP_LOOP){
            if(cmd[2])
                POP_Up_Cycle = cmd[2];  //Range:1~255
            else
                POP_Up_Cycle = 12;      //Default:12s
        }
        else{
            void PNS_SOLENOID_CTRL(void);
            PNS_SOLENOID_CTRL();    //Solenoid Control function
        }
        break;
#if SUPPORT_UAC
    case 0x12:
        if(cmd[1] == 0x81){
            eu1_get_mmp_result_val[1] = GTKLIB_EN;
        }
        else if(cmd[1] == 0x01){
            GTKLIB_EN = cmd[2];     //Goertek lib enable
        }
        dbg_printf(3, "# Goertek lib On/Off:%d", GTKLIB_EN);
        break;
#endif
#endif
#if SUPPORT_AIT845x_MD  //for Codetak command
#if (CUSTOMER == ANW)
    case 0x20:  // Set Motion Detection Mask Area, 5x5 block area
        {
            //cmd[1]:Enable  cmd[2]:X  cmd[3]:Y
            MMP_BOOL IsPreviewEnable;

            if((cmd[2]>4)||(cmd[3]>4)) {
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                dbg_printf(3,"#Set MD windows WxH is error:5x5\r\n");
            }
            else {
                MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
                MD_Block[cmd[2]+cmd[3]*5] = cmd[1];
                if(IsPreviewEnable) {
                    ChangeMDEn = 1;
                }
                else {
                    dbg_printf(3,"@Set MD(%d,%d) Enable:%d\r\n", cmd[2], cmd[3], cmd[1]);
                }
            }
        }
        break;
    case 0x21:  // Set Motion Detection Sensitivity, range is from 0 to 100
        {
            //cmd[1]:Sensitivity
            MMP_BOOL IsPreviewEnable;
            if(cmd[1]>100) {
                eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                dbg_printf(3,"#Set MD sensitivity range is error:0~100\r\n");
            }
            else {
                if(cmd[1] == 0) {
                    MD_sensitivity = cmd[1];
                    ChangeMDprs = 1;
                }
                else {
                    /*if(cmd[1] >= 90){   //for ANW map
                        MD_sensitivity = 7 - (cmd[1] - 90) / 2;
                    }
                    else{
                        MD_sensitivity = 8 + (90 - cmd[1]) / 3;
                    }*/

                    if (cmd[1] > 100)
                        MD_sensitivity = 100;
                    else
                        MD_sensitivity = cmd[1];

                    MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
                    if(IsPreviewEnable) {
                        ChangeMDprs = 1;
                    }
                    else {
                        dbg_printf(3,"@Set MD Sensitivity:%d\r\n", MD_sensitivity);
                    }
                }
            }
        }
        break;
#else
    case 0x1E:
        {
            //cmd[1]: 0x01:Set MD the cutting windows   0xFF:Reset MD default setting
            //cmd[2]: [0x01]:X_div  [0xFF]:Null
            //cmd[3]: [0x01]:Y_div  [0xFF]:Null
            MMP_BOOL IsPreviewEnable;

            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if(IsPreviewEnable) {
                if(cmd[1] == 0x01) {
                    MMP_ULONG mdbufsize=0, mdbufaddr=0;

                    if((cmd[2]>16)||(cmd[3]>12)) {
                        eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                        dbg_printf(3,"@Set MD windows WxH is error:%dx%d\r\n", MD_x_div, MD_y_div);
                    }
                    else {
                        MD_x_div = cmd[2];
                        MD_y_div = cmd[3];

                        mdbufsize = MD_get_buffer_info(MD_x_res, MD_y_res, 1/*1:Y only*/, MD_x_div, MD_y_div);
                        mdbufaddr = MD_address;//(MMP_ULONG)MMPF_SYS_AllocFB("MD",mdbufsize,32);
                        MD_init((MMP_UBYTE *)mdbufaddr, mdbufsize, MD_x_res, MD_y_res, 1/*1:Y only*/);
                        MD_set_detect_window(0, 0, MD_x_res-1, MD_y_res-1, MD_x_div, MD_y_div);
                        dbg_printf(3,"#Set MD windows WxH:%dx%d\r\n", MD_x_div, MD_y_div);
                    }
                }
                else if(cmd[1] == 0xFF) {
                    MD_params_in_t MD_prs = {1, 5, 100, 90, 2000};
                    MMP_ULONG mdbufsize=0, mdbufaddr=0, i;
                    MD_x_div = MD_y_div = 5;
                    mdbufsize = MD_get_buffer_info(MD_x_res, MD_y_res, 1/*1:Y only*/, MD_x_div, MD_y_div);
                    mdbufaddr = MD_address;//(MMP_ULONG)MMPF_SYS_AllocFB("MD",mdbufsize,32);
                    MD_init((MMP_UBYTE *)mdbufaddr, mdbufsize, MD_x_res, MD_y_res, 1/*1:Y only*/);
                    MD_set_detect_window(0, 0, MD_x_res-1, MD_y_res-1, MD_x_div, MD_y_div);
                    for(i=0; i<(MD_x_div*MD_y_div); i++) {
                        //for init md params in
                        MD_set_window_params_in(i%MD_x_div, i/MD_x_div, &MD_prs);
                    }
                    dbg_printf(3,"Reset MD:X_div(5) Y_div(5) Sensitivity(17)\r\n");
                }
            }
            else {
                if(cmd[1] == 0x01) {
                    if((cmd[2]>16)||(cmd[3]>12)) {
                        eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                        dbg_printf(3,"@Set MD windows WxH is error:%dx%d\r\n", MD_x_div, MD_y_div);
                    }
                    else {
                        MD_x_div = cmd[2];
                        MD_y_div = cmd[3];
                        dbg_printf(3,"@Set MD windows WxH:%dx%d\r\n", MD_x_div, MD_y_div);
                    }
                }
                else if(cmd[1] == 0xFF) {
                    dbg_printf(3,"@MD has not been working!!!\r\n");
                }
            }
        }
        break;
    case 0x1F:
        {
            //cmd[1]: 0x02:Set MD sensitivity
            //cmd[2]: MD Number_L
            //cmd[3]: MD Number_H
            //cmd[4]: sensitivity(0~40)
            MMP_BOOL IsPreviewEnable;
            MD_params_in_t MD_prs = {1, 5, 100, 90, 2000};

            MD_Number = (cmd[3]<<8) + cmd[2];
            MD_sensitivity = cmd[4];

            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if(IsPreviewEnable) {
                if(cmd[1]==0x02) {
                    MD_prs.sensitivity = MD_sensitivity;
                    if(MD_prs.sensitivity==0)
                        MD_prs.enable = 0;
                    else
                        MD_prs.enable = 1;
                    MD_set_window_params_in(MD_Number%MD_x_div, MD_Number/MD_x_div, &MD_prs);
                    dbg_printf(3,"#Set MD (%d,%d) Sensitivity:%d\r\n", MD_Number%MD_x_div, MD_Number/MD_x_div, MD_sensitivity);
                }
            }
            else {
                if(cmd[1]==0x02) {
                    MMP_ULONG i;
                    //MD_sensitivity_number[0] save the MD set number and bit[15] is enable.
                    MD_sensitivity_number[0] |= 0x8000;
                    MD_sensitivity_number[0]++;
                    for(i=0; i<16*12; i++) {
                        if(MD_sensitivity_number[i+1]==0) {
                            MD_sensitivity_number[i+1] = MD_Number;
                            MD_sensitivity_data[i] = MD_sensitivity;
                            break;
                        }
                    }
                    dbg_printf(3,"@Set MD (%d,%d) Sensitivity:%d\r\n", MD_Number%MD_x_div, MD_Number/MD_x_div, MD_sensitivity);
                }
            }
        }
        break;
#endif
#endif
#if (SUPPORT_H264MV_MD)
    case 0x20:  // Set Motion Detection Mask Area, 5x5 block area
        {
            MMP_USHORT MBWidth, MBHeight, BlockX, BlockY;
            MMP_USHORT i, j, offsetX, offsetY;
            MMP_BOOL bEnable;

            bEnable = cmd[1];
            if((cmd[2] >= MD_BLOCK_X_NUM) && (cmd[3] >= MD_BLOCK_Y_NUM)){
                MD_SetAllAreaMask(bEnable);
            }
            else{ 
                BlockX = (((cmd[2]) > (MD_BLOCK_X_NUM-1)) ? (MD_BLOCK_X_NUM-1) : (cmd[2]));
                BlockY = (((cmd[3]) > (MD_BLOCK_Y_NUM-1)) ? (MD_BLOCK_Y_NUM-1) : (cmd[3]));
                MD_GetMBRngBd(&MBWidth, &MBHeight);
                offsetX = (MBWidth + MD_BLOCK_X_NUM - 1) / MD_BLOCK_X_NUM;
                offsetY = (MBHeight + MD_BLOCK_Y_NUM - 1) / MD_BLOCK_Y_NUM;
            
                for(j = BlockY*offsetY ; j < (BlockY+1)*offsetY ; j++){
                    for(i = BlockX*offsetX ; i < (BlockX+1)*offsetX ; i++){
                        MD_SetAreaMask(i, j, bEnable);
                    }
                }
            }
        }
        break;
    case 0x21:  // Set Motion Detection Sensitivity, range is from 0 to 100
        {
            MD_SetMDSensitivity(cmd[1]);
        }
        break;
#endif
    case 0x24:  //For Foscam : Set NR(Noise Reduction) Level
        //cmd[1] : Get/Set NR level => 0:Get 1:Set
        //cmd[2] : NR level offset  => -8 ~ 8
        if(cmd[1]) {
            if(cmd[2]>0xF7) {
                MMP_LONG val[8] = {-8,-7,-6,-5,-4,-3,-2,-1};
                ISP_IF_IQ_SetIDOffset(ISP_IQ_CHECK_CLASS_GAIN, val[cmd[2]-0xF8]);
                eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_OK;
                dbg_printf(3,"Set NR level:%d\r\n",val[cmd[2]-0xF8]);
            }
            else if(cmd[2]<0x09) {
                ISP_IF_IQ_SetIDOffset(ISP_IQ_CHECK_CLASS_GAIN, cmd[2]);
                eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_OK;
                dbg_printf(3,"Set NR level: %d\r\n",cmd[2]);
            }
            else {
                eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                dbg_printf(3,"Input NR is error[x%X]!!!\r\n",cmd[2]);
            }
        }
        else {
            volatile MMP_UBYTE *REG_BASE_B = (volatile MMP_UBYTE *) (0x80000000);
            MMP_USHORT NR_Level = 0;
            NR_Level = REG_BASE_B[0x0D28] - 0x11;
            eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_OK;
            eu1_get_mmp_cmd16_result_val[1] = NR_Level;
            dbg_printf(3,"Get NR level:%d\r\n",NR_Level);
        }
        break;
#if (CUSTOMER == ANW)
    case 0x50:  //Not use
        {
            MMPF_I2CM_ATTRIBUTE m_CG5162TC_I2cmAttribute = {MMPF_I2CM_ID_0, 0x10, 8, 8, 0, MMP_FALSE, MMP_FALSE, MMP_FALSE, MMP_FALSE, 0, 0, 0, MMPF_I2CM_SPEED_HW_250K, NULL, NULL};
            MMP_USHORT usCH0=0, usCH1=0, usCGAIN=0, usTIG_SEL=0, usData=0;
            MMPF_I2cm_Initialize(&m_CG5162TC_I2cmAttribute);
            MMPF_I2cm_ReadReg(&m_CG5162TC_I2cmAttribute, 0x20, (MMP_USHORT *)&usData);
            dbg_printf(3,"Reset:0x%X\r\n",usData);
            MMPF_OS_Sleep_MS(10);
            MMPF_I2cm_ReadReg(&m_CG5162TC_I2cmAttribute, 0x21, (MMP_USHORT *)&usCH0);  //CH0 LB
            usData = usCH0;
            dbg_printf(3,"CH0LB:0x%X\r\n",usData);
            MMPF_I2cm_ReadReg(&m_CG5162TC_I2cmAttribute, 0x22, (MMP_USHORT *)&usCH0);  //CH0 HB
            usCH0 = (usCH0<<8) + usData;
            dbg_printf(3,"CH0:0x%X\r\n",usCH0);
            MMPF_I2cm_ReadReg(&m_CG5162TC_I2cmAttribute, 0x23, (MMP_USHORT *)&usCH1);  //CH1 LB
            usData = usCH1;
            dbg_printf(3,"CH1LB:0x%X\r\n",usData);
            MMPF_I2cm_ReadReg(&m_CG5162TC_I2cmAttribute, 0x24, (MMP_USHORT *)&usCH1);  //CH1 HB
            usCH1 = (usCH1<<8) + usData;
            dbg_printf(3,"CH1:0x%X\r\n",usCH1);
            MMPF_I2cm_ReadReg(&m_CG5162TC_I2cmAttribute, 0x05, (MMP_USHORT *)&usCGAIN);
            usCGAIN = usCGAIN>>4;
            dbg_printf(3,"CGAIN_0:0x%X\r\n",usCGAIN);
            MMPF_I2cm_ReadReg(&m_CG5162TC_I2cmAttribute, 0x04, (MMP_USHORT *)&usTIG_SEL);
            dbg_printf(3,"TIG_SEL:0x%X\r\n",usTIG_SEL);

            if(usCH0 == 0xFFFF) {
                usData = usCH0 * (15 / usCGAIN) * (148 / usTIG_SEL) * 0.022;
            }
            else {
                usData = (usCH0 - usCH1) * (15 / usCGAIN) * (148 / usTIG_SEL) * 0.022;
            }
            dbg_printf(3,"lux:0x%X\r\n",usData);
            eu1_get_mmp_cmd16_result_val[0] = EU_ISP_CMD_OK;
            eu1_get_mmp_cmd16_result_val[1] = usData;
            eu1_get_mmp_cmd16_result_val[2] = usData>>4;
        }
        break;
    case 0x60:
        // set flicker mode, 0: auto, 1: 50Hz, 2: 60Hz, 3: auto_limitexpo, 4: 50Hz_limitexpo, 5: 60Hz_limitexpo
        if(cmd[1] == 0x01)
            gbBandFilter = BAND_50HZ;
        else if(cmd[1] == 0x02)
            gbBandFilter = BAND_60HZ;
        else if(cmd[1] == 0x03)
            gbBandFilter = BAND_AUTO_LE;
        else if(cmd[1] == 0x04)
            gbBandFilter = BAND_50HZ_LE;
        else if(cmd[1] == 0x05)
            gbBandFilter = BAND_60HZ_LE;
        else
            gbBandFilter = BAND_DISABLE;

        RTNA_DBG_Str(3, "  ** USB Light Freq Set : ");
        RTNA_DBG_Short(3, gbBandFilter);
        RTNA_DBG_Str(3, "\r\n");

        USB_SetPowerLineFreq(PCAM_NONBLOCKING, gbBandFilter);
        break;
#endif
    case 0xFF:
        switch(cmd[1]){
#if BIND_SENSOR_OV9726 || BIND_SENSOR_OV9710 || BIND_SENSOR_AR0330 || BIND_SENSOR_OV5650
        extern MMP_USHORT gsEnableTestPattern;    //for OV9726/OV9712/AR0330/OV5650
        case 0x01:
            //H.264 test
            gsEnableTestPattern = cmd[2];
            break;
#endif
        case 0x03:
            //DRAM test
            usb_ep0_null_in();
            MMPF_SYS_SelfRomBoot();
            break;
#if SUPPORT_PU_DEFAULT
        case 0x05:
            {
                //Reset PU flash
                extern MMP_ULONG pu_sf_addr;
                MMPF_SF_InitialInterface();
                MMPF_SF_EraseSector(pu_sf_addr);
                dbg_printf(3,"Reset PU flash!!!\r\n");
            }
            break;
#endif
        }
        break;
    default:
        eu1_get_mmp_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
        break;
    }
}

#if 1
void usb_vc_eu1_isp_ex_cmd(MMP_UBYTE *cmd)//cmd -> 8byte
{
    MMP_ULONG Ret = 0;

    //dbg_printf(2, "isp cmd ex %02X %02X %02X %02X %02X\r\n", cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]);
    //eu1_get_isp_ex_result_val[0] = 0;
    switch(cmd[0]){
#if 0   //only ISPIQ_GET_AWB_TEMPRET
    case ISPIQ_GET_PREVIEW_GAIN_ID:
        eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetID(ISP_IQ_CONDITION_PREVIEW, ISP_IQ_CHECK_CLASS_GAIN);
        //eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetPreviewGID();
        break;
    case ISPIQ_GET_CAPTURE_GAIN_ID:
        eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetID(ISP_IQ_CONDITION_CAPTURE, ISP_IQ_CHECK_CLASS_GAIN);
        //eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetCaptureGID();
        break;
    case ISPIQ_GET_PREVIEW_ENGERY_ID:
        eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetID(ISP_IQ_CONDITION_PREVIEW, ISP_IQ_CHECK_CLASS_ENERGY);
        //eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetPreviewEID();
        break;
    case ISPIQ_GET_CAPTURE_ENGERY_ID:
        eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetID(ISP_IQ_CONDITION_CAPTURE, ISP_IQ_CHECK_CLASS_ENERGY);
        //eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetCaptureEID();
        break;
    case ISPIQ_SET_AWB_MODE:
        //ISP_IF_AWB_SetMode(cmd[1]);
        switch (cmd[1]) {
        case 0: // bypass
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_BYPASS);
            break;
        case 1: // auto
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_AUTO);
            break;
        case 2: // cloudy
            ISP_IF_AWB_SetColorTemp(7500);
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);
            break;
        case 3: // daylight
            ISP_IF_AWB_SetColorTemp(6500);
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);
            break;
        case 4: // coolwhite
            ISP_IF_AWB_SetColorTemp(3400);
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);
            break;
        case 5: // alight
            ISP_IF_AWB_SetColorTemp(2800);
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);
            break;
        case 6: // fluorescent
            ISP_IF_AWB_SetColorTemp(3400);
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);
            break;
        case 7: // effect
            ISP_IF_AWB_SetColorTemp(6500);
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);
            break;
        case 8: // dawn
            ISP_IF_AWB_SetColorTemp(6500);
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);
            break;
        case 9: // sunset
            ISP_IF_AWB_SetColorTemp(6500);
            ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);
            break;
        }
        break;
    case ISPIQ_GET_PREVIEW_TEMP_ID:
        eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetID(ISP_IQ_CONDITION_PREVIEW, ISP_IQ_CHECK_CLASS_COLORTEMP);
        break;
    case ISPIQ_GET_CAPTURE_TEMP_ID:
        eu1_get_isp_ex_result_val[1] = ISP_IF_IQ_GetID(ISP_IQ_CONDITION_CAPTURE, ISP_IQ_CHECK_CLASS_COLORTEMP);
        break;
    case ISPIQ_SELECT_DBG_TABLE:
        {

            #if DRAW_TEXT_FEATURE_EN
            MMP_USHORT sheet_no;
            MMP_USHORT table_no;
            sheet_no = cmd[1]+cmd[2]*0x100;
            table_no = cmd[3]+cmd[4]*0x100;
            _sprintf(gDrawTextBuf,"Select Table sheet=%X table=%X\r\n",sheet_no,table_no);
            RTNA_DBG_Str(0,gDrawTextBuf);
            #endif

            ISP_IF_DBG_GetTable(cmd[1]+cmd[2]*0x100,cmd[3]+cmd[4]*0x100);
            break;
        }
    case ISPIQ_SET_DBG_TABLE_BY_INDEX:
        {
            ISP_IF_DBG_SetTableByIndex(cmd[1]+cmd[2]*0x100);
            break;
        }
    case ISPIQ_GET_DBG_TBL_ROWS:
        {
            Ret = ISP_IF_DBG_GetTableRows();
            eu1_get_isp_ex_result_val[1] = Ret&0xFF;
            eu1_get_isp_ex_result_val[2] = (Ret>>8)&0xFF;
            break;
        }
    case ISPIQ_GET_DBG_TBL_COLS:
        {
            Ret = ISP_IF_DBG_GetTableCols();
            eu1_get_isp_ex_result_val[1] = Ret&0xFF;
            eu1_get_isp_ex_result_val[2] = (Ret>>8)&0xFF;
            break;
        }
    case ISPIQ_GET_DBG_TBL_TYPE:
        {
            eu1_get_isp_ex_result_val[1] = ISP_IF_DBG_GetTableType();
            break;
        }
    case ISPIQ_GET_DBG_TBL_MODE:
        {
            eu1_get_isp_ex_result_val[1] = ISP_IF_DBG_GetTableMode();
            break;
        }
    case ISPIQ_GET_DBG_TBL_VALUE:
        {
            Ret = ISP_IF_DBG_GetTableValue();
            eu1_get_isp_ex_result_val[1] = Ret&0xFF;
            eu1_get_isp_ex_result_val[2] = (Ret>>8)&0xFF;
            eu1_get_isp_ex_result_val[3] = (Ret>>16)&0xFF;
            eu1_get_isp_ex_result_val[4] = (Ret>>24)&0xFF;
            break;
        }
    case ISPIQ_GET_DBL_TBL_START_ADDR:
        {
            //Ret = ISP_IF_DBG_GetTableStartAddr();
            Ret = ISP_HDM_IF_GetTableDstAddr();

            #if DRAW_TEXT_FEATURE_EN
            _sprintf(gDrawTextBuf,"Get DestAddr %X \r\n",Ret);
            RTNA_DBG_Str(0,gDrawTextBuf);
            #endif

            eu1_get_isp_ex_result_val[1] = Ret&0xFF;
            eu1_get_isp_ex_result_val[2] = Ret>>8&0xFF;
            eu1_get_isp_ex_result_val[3] = Ret>>16&0xFF;
            eu1_get_isp_ex_result_val[4] = Ret>>24&0xFF;
            break;
        }
    case ISPIQ_GET_DBG_TBL_APTOOL_ADDR:
        {
            //Ret = ISP_HDM_IF_GetTableDstAddr();
            Ret = ISP_HDM_IF_GetTableApToolBufAddr();

            #if DRAW_TEXT_FEATURE_EN
            _sprintf(gDrawTextBuf,"Get ApToolAddr %X \r\n",Ret);
            RTNA_DBG_Str(0,gDrawTextBuf);
            #endif

            eu1_get_isp_ex_result_val[1] = Ret&0xFF;
            eu1_get_isp_ex_result_val[2] = Ret>>8&0xFF;
            eu1_get_isp_ex_result_val[3] = Ret>>16&0xFF;
            eu1_get_isp_ex_result_val[4] = Ret>>24&0xFF;
            break;
        }
    case ISPIQ_GET_DBL_TBL_TOTAL_SIZE:
        {
            Ret = ISP_IF_DBG_GetTableTotalSize();
            eu1_get_isp_ex_result_val[1] = Ret&0xFF;
            eu1_get_isp_ex_result_val[2] = Ret>>8&0xFF;
            eu1_get_isp_ex_result_val[3] = Ret>>16&0xFF;
            eu1_get_isp_ex_result_val[4] = Ret>>24&0xFF;
            break;
        }
    case ISPIQ_WRITE_MEM_PARAM:
        {
            WriteMemAddr = eu1_set_isp_ex_val[1]
                         + eu1_set_isp_ex_val[2]*0x100
                         + eu1_set_isp_ex_val[3]*0x10000
                         + eu1_set_isp_ex_val[4]*0x1000000;
            WriteMemCount = eu1_set_isp_ex_val[5]
                         + eu1_set_isp_ex_val[6]*0x100
                         + eu1_set_isp_ex_val[7]*0x10000
                         + eu1_set_isp_ex_val[8]*0x1000000;
            break;
        }
    case ISPIQ_WRITE_MEM:
        {
            MMP_UBYTE n;
            MMP_UBYTE wlen;
            if(WriteMemCount>15)
                wlen = 15;
            else
                wlen = WriteMemCount;

            WriteMemCount -= wlen;

            for(n=0;n<wlen;++n)
            {
                ((MMP_BYTE*)WriteMemAddr)[n] = eu1_set_isp_ex_val[n+1];
            }
            WriteMemAddr += wlen;
            break;
        }
    case ISPIQ_READ_MEM_PARAM:
        {
            ReadMemAddr = eu1_set_isp_ex_val[1]
                         + eu1_set_isp_ex_val[2]*0x100
                         + eu1_set_isp_ex_val[3]*0x10000
                         + eu1_set_isp_ex_val[4]*0x1000000;
            ReadMemCount = eu1_set_isp_ex_val[5]
                         + eu1_set_isp_ex_val[6]*0x100
                         + eu1_set_isp_ex_val[7]*0x10000
                         + eu1_set_isp_ex_val[8]*0x1000000;
            break;
        }
    case ISPIQ_READ_MEM:
        {
            MMP_UBYTE n;
            MMP_UBYTE rlen;
            if(ReadMemCount>15)
                rlen = 15;
            else
                rlen = ReadMemCount;

            ReadMemCount -= rlen;

            for(n=0;n<rlen;++n)
            {
                 eu1_get_isp_ex_result_val[n+1] = ((MMP_BYTE*)ReadMemAddr)[n];
            }
            ReadMemAddr += rlen;
            break;
        }
    case ISPIQ_MOVE_MEM:
        {
            int n;
            MMP_UBYTE *src;
            MMP_UBYTE *dest;
            MMP_ULONG Size;

            ((MMP_ULONG)src)    = eu1_set_isp_ex_val[1]
                                + eu1_set_isp_ex_val[2]*0x100
                                + eu1_set_isp_ex_val[3]*0x10000
                                + eu1_set_isp_ex_val[4]*0x1000000;
            ((MMP_ULONG)dest)   = eu1_set_isp_ex_val[5]
                                + eu1_set_isp_ex_val[6]*0x100
                                + eu1_set_isp_ex_val[7]*0x10000
                                + eu1_set_isp_ex_val[8]*0x1000000;
            Size = eu1_set_isp_ex_val[9]
                 + eu1_set_isp_ex_val[10]*0x100
                 + eu1_set_isp_ex_val[11]*0x10000
                 + eu1_set_isp_ex_val[12]*0x1000000;

#if DRAW_TEXT_FEATURE_EN
            _sprintf(gDrawTextBuf,"CopyMemory: Src=%x Dst=%x Size=%x \r\n",(MMP_ULONG)src,(MMP_ULONG)dest,(MMP_ULONG)Size);
            RTNA_DBG_Str(0,gDrawTextBuf);
#endif

            for(n=0;n<Size;++n)
            {
                dest[n] = src[n];
            }

#if DRAW_TEXT_FEATURE_EN
            _sprintf(gDrawTextBuf,"src[0-4]=%X,%X,%X,%X\r\n",src[0],src[1],src[2],src[3]);
            RTNA_DBG_Str(0,gDrawTextBuf);
            _sprintf(gDrawTextBuf,"dest[0-4]=%X,%X,%X,%X\r\n",dest[0],dest[1],dest[2],dest[3]);
            RTNA_DBG_Str(0,gDrawTextBuf);
#endif

            break;
        }
    case ISPIQ_SET_AE_ISO:
        {
            ISP_IF_AE_SetISO(cmd[1]);
            break;
        }

    case ISPIQ_GET_AWB_GAIN:
        {
            Ret = ISP_IF_AWB_GetGainR();
            eu1_get_isp_ex_result_val[1] = Ret & 0xFF;
            eu1_get_isp_ex_result_val[2] = (Ret>>8) & 0xFF;
            Ret = ISP_IF_AWB_GetGainG();
            eu1_get_isp_ex_result_val[3] = Ret & 0xFF;
            eu1_get_isp_ex_result_val[4] = (Ret>>8) & 0xFF;
            Ret = ISP_IF_AWB_GetGainB();
            eu1_get_isp_ex_result_val[5] = Ret & 0xFF;
            eu1_get_isp_ex_result_val[6] = (Ret>>8) & 0xFF;
            break;
        }

    case ISPIQ_GET_LIGHT_COND_VAL:
        {
            Ret = ISP_IF_AE_GetLightCond();
            eu1_get_isp_ex_result_val[1] = Ret & 0xFF;
            eu1_get_isp_ex_result_val[2] = (Ret>>8) & 0xFF;
            eu1_get_isp_ex_result_val[3] = (Ret>>16) & 0xFF;
            eu1_get_isp_ex_result_val[4] = (Ret>>24) & 0xFF;
            break;
        }

    case ISPIQ_GET_AE_ENERGY:
        {
            Ret = ISP_IF_AE_GetPreEnergy();
            eu1_get_isp_ex_result_val[1] = Ret & 0xFF;
            eu1_get_isp_ex_result_val[2] = (Ret>>8) & 0xFF;
            eu1_get_isp_ex_result_val[3] = (Ret>>16) & 0xFF;
            eu1_get_isp_ex_result_val[4] = (Ret>>24) & 0xFF;
            break;
        }

    case ISPIQ_SET_IQ_SWITCH:
        {
            ISP_IF_IQ_SetSwitch(cmd[1], cmd[2]);
            break;
        }

    case ISPIQ_GET_AE_BASE_SHUTTER:
        {
            Ret = ISP_IF_AE_GetBaseShutter();
            eu1_get_isp_ex_result_val[1] = Ret & 0xFF;
            eu1_get_isp_ex_result_val[2] = (Ret>>8) & 0xFF;
            eu1_get_isp_ex_result_val[3] = (Ret>>16) & 0xFF;
            eu1_get_isp_ex_result_val[4] = (Ret>>24) & 0xFF;
            break;
        }
#endif
    case ISPIQ_GET_AWB_TEMPRET:
        //GET AWB COLOR TEMPRET
         {
            Ret = ISP_IF_AWB_GetColorTemp();
            eu1_get_isp_ex_result_val[1] = Ret & 0xFF;
            eu1_get_isp_ex_result_val[2] = (Ret >> 8) & 0xFF;
            eu1_get_isp_ex_result_val[3] = (Ret >> 16) & 0xFF;
            eu1_get_isp_ex_result_val[4] = (Ret >> 24) & 0xFF;
#if DRAW_TEXT_FEATURE_EN
            //_sprintf(gDrawTextBuf,"Temp. %d K",Ret);
            //dbg_printf(0, "gDrawTextBuf:%d\r\n",*(MMP_ULONG*)(gDrawTextBuf + 6));
            //RTNA_DBG_Str(0,gDrawTextBuf);
#endif
            dbg_printf(0, "Temp. %d K\r\n", Ret);
            break;
        }
    }
}
#endif

void usb_vc_eu1_cs_out(void)
{
    MMP_UBYTE cs,len;
    MMP_USHORT i;
    //MMP_ULONG  tmp2 = 0;
    //MMP_ULONG  tmp4 = 0;
    AITPS_USB_CTL pUSB_CTL = AITC_BASE_USBCTL;


    cs = (UsbRequestPayload_wValue >> 8);
    len = UsbRequestPayload_wLength;

    switch(cs){
    case EU1_SET_ISP:
        USBOutData = 0;
        for(i = 0;i < EU1_SET_ISP_LEN;++i){
            eu1_set_isp_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        usb_vc_eu1_isp_cmd(eu1_set_isp_val);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU1_GET_ISP_RESULT:
        USBOutData = 0;
        for(i = 0;i < EU1_GET_ISP_RESULT_LEN;++i){
            eu1_get_isp_result_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;
    case EU1_SET_FW_DATA:
        //set fw data
         {
            MMP_UBYTE FWDataBuf[EU1_SET_FW_DATA_LEN];
            USBOutData = 0;
            for(i = 0;i < EU1_SET_FW_DATA_LEN;++i){
                //MMP_UBYTE tmp = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
                FWDataBuf[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
            }
            //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
            USB_DownloadFWData(FWDataBuf, EU1_SET_FW_DATA_LEN);
            USBInPhase = SET_CUR_CMD;
            usb_ep0_null_in();
        }break;
    case EU1_SET_MMP:
        //
        USBOutData = 0;
        for(i = 0;i < EU1_SET_MMP_LEN;++i){
            eu1_set_mmp_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        usb_vc_eu1_mmp_cmd(eu1_set_mmp_val);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;
    case EU1_GET_MMP_RESULT:
        USBOutData = 0;
        for(i = 0;i < EU1_GET_MMP_RESULT_LEN;++i){
            eu1_get_mmp_result_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU1_SET_MMP_CMD16:
        //
        USBOutData = 0;
        for(i = 0;i < EU1_SET_MMP_CMD16_LEN;++i){
            eu1_set_mmp_cmd16_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        usb_vc_eu1_mmp_cmd16(eu1_set_mmp_cmd16_val);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU1_GET_MMP_CMD16_RESULT:
        //
        USBOutData = 0;
        for(i = 0;i < EU1_GET_MMP_CMD16_RESULT_LEN;++i){
            eu1_get_mmp_cmd16_result_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        //usb_vc_eu1_mmp_cmd16(eu1_get_mmp_cmd16_result_val);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU1_SET_ISP_EX:
        USBOutData = 0;
        for(i = 0;i < EU1_SET_ISP_EX_LEN;++i){
            eu1_set_isp_ex_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        usb_vc_eu1_isp_ex_cmd(eu1_set_isp_ex_val);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;

    case EU1_GET_ISP_EX_RESULT:
        USBOutData = 0;
        for(i = 0;i < EU1_GET_ISP_EX_RESULT_LEN;++i){
            eu1_get_isp_ex_result_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;
    case EU1_WRITE_MMP_MEM:
         {
            MMP_UBYTE n;
            MMP_UBYTE wlen;
            MMP_UBYTE Buf[EU1_WRITE_MMP_MEM_LEN];

            for(n = 0;n < EU1_WRITE_MMP_MEM_LEN;++n){
                Buf[n] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
            }

            if(WriteMemCount > EU1_WRITE_MMP_MEM_LEN)
                wlen = EU1_WRITE_MMP_MEM_LEN;
            else
                wlen = WriteMemCount;

            WriteMemCount -= wlen;

            for(n = 0;n < wlen;++n){
                ((MMP_BYTE *) WriteMemAddr)[n] = Buf[n];
            }
            WriteMemAddr += wlen;

            USBOutData = 0;
            USBInPhase = SET_CUR_CMD;
            usb_ep0_null_in();
            break;
        }
    case EU1_GET_CHIP_INFO:
        USBOutData = 0;
        for(i = 0;i < EU1_GET_CHIP_INFO_LEN;++i){
            eu1_get_chip_info_val[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
        }
        //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;
    case EU1_SET_DATA_32:
         {
    		MMP_UBYTE tmp[EU1_SET_DATA_32_LEN];
            USBOutData = 0;    
            USB_GET_FIFO_DATA(MMPF_USB_EP0,len,tmp,sizeof(tmp)) ;
            #if (SUPPORT_OSD_FUNC)
            if(bEnableSetData32Transfer) {
                MMP_SHORT nStrLen = STRLEN((MMP_BYTE*)tmp);
                pcam_Osd_SetTextString((MMP_BYTE*)tmp, ((nStrLen)>EU1_SET_DATA_32_LEN)?EU1_SET_DATA_32_LEN:nStrLen);
                bEnableSetData32Transfer = MMP_FALSE;
            }
            #endif
            //UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
            USBInPhase = SET_CUR_CMD;
            usb_ep0_null_in();
            break;
        }

#if (CUSTOMER == CCN) || (CUSTOMER == LON) || (CUSTOMER == ASU)
    case EU1_ACCESS_CUSTOMER_DATA:
         {
            //MMP_ULONG NVMAddr;
            MMP_UBYTE NVMCmd;
            MMP_UBYTE NVMLen;
            USBOutData = 0;
            gsNVMAddr = (MMP_USHORT) (pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B);
            gsNVMAddr |= ((MMP_USHORT) pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B << 8);
            NVMCmd = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
            NVMLen = NVMCmd & 0x3F;
            NVMCmd &= 0xC0;

            for(i = 0;i < (len - 3);i++){
                if(NVMCmd == 0x00) // normal write
                {
                    //read data to buffer
                    if(i < NVMLen){
                        *(MMP_UBYTE *) (CustomDataRwBuf + i) = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
                    }
                    else{
                        MMP_UBYTE tmpb;
                        tmpb = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
                    }
                }
                else{
                    MMP_UBYTE tmpb;
                    tmpb = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B;
                }
            }

            if(NVMCmd == 0xC0){
                //erase
                //MMPF_SIF_Init();
                if(USB_ResetFlash()){
#if (EN_DBGLOG_FOR_FLASH)
                    RTNA_DBG_Str(0, "\r\nSIF init error !!\r\n");
#endif
                }
                MMPF_SF_EraseSector(CUSTOMER_INIT_FLASH_ADDR & 0xFFFFF000);
            }
            else if(NVMCmd == 0x00){
                //
                //MMPF_SIF_Init();
                if(USB_ResetFlash()){
#if (EN_DBGLOG_FOR_FLASH)
                    RTNA_DBG_Str(0, "\r\nSIF init error !!\r\n");
#endif
                }
                MMPF_SIF_WriteDataEx(CUSTOMER_INIT_FLASH_ADDR + gsNVMAddr, (MMP_ULONG) CustomDataRwBuf, NVMLen);
            }
#if 0//USE_COMMON_EP0_OUT
   usb_vc_finish_set_cur();
#else
    USBInPhase = SET_CUR_CMD;
    usb_ep0_null_in();
#endif
        }
        break;
#endif
    case XU_CONTROL_UNDEFINED:
    default:
        // impossible flow
        break;
    }
}


//
// XU2 : TBD for customer XU
//
//#if USB_UVC_H264==1 || SKYPE_UVC_H264
#if SKYPE_MODE_B || USB_MJPEGH264_STREAM
extern H264_ENCODER_VFC_CFG gsH264EncoderVFC_Cfg_Cur;
/*
VC_CMD_CFG VC_XU_VIDEO_FORMAT_CFG = {
    ( CAP_SET_CUR_CMD | CAP_GET_INFO_CMD |CAP_GET_CUR_CMD |CAP_GET_DEF_CMD | CAP_GET_LEN_CMD),
    ( INFO_GET_SUPPORT | INFO_SET_SUPPORT),
    XU_ENCODER_VIDEO_FORMAT_LEN,1,
    0,(MMP_ULONG)&gsH264EncoderVFC_Cfg_Def,0,0,(MMP_ULONG)&gsH264EncoderVFC_Cfg_Cur
} ;

VC_CMD_CFG VC_XU_VIDEO_CONFIG_CFG = {
    ( CAP_SET_CUR_CMD | CAP_GET_INFO_CMD |CAP_GET_CUR_CMD |CAP_GET_DEF_CMD | CAP_GET_LEN_CMD),
    ( INFO_GET_SUPPORT | INFO_SET_SUPPORT),
    XU_ENCODER_CONFIGURATION_LEN,1,
    0,(MMP_ULONG)&gsH264EncoderCC_Cfg_Def,0,0,(MMP_ULONG)&gsH264EncoderCC_Cfg_Cur
} ;

VC_CMD_CFG VC_XU_VIDEO_RATECTL_CFG = {
    ( CAP_SET_CUR_CMD | CAP_GET_INFO_CMD |CAP_GET_CUR_CMD |CAP_GET_DEF_CMD | CAP_GET_LEN_CMD | CAP_GET_MIN_CMD | CAP_GET_MAX_CMD),
    ( INFO_GET_SUPPORT | INFO_SET_SUPPORT),
    XU_RATE_CONTROL_LEN,1,
    0,
    (MMP_ULONG)&gsH264EncoderRC_Cfg_Def,
    (MMP_ULONG)&gsH264EncoderRC_Cfg_Min,
    (MMP_ULONG)&gsH264EncoderRC_Cfg_Max,
    (MMP_ULONG)&gsH264EncoderRC_Cfg_Cur
} ;

VC_CMD_CFG VC_XU_VIDEO_FRAMETYPE_CFG = {
    ( CAP_SET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_LEN_CMD),
    ( INFO_GET_SUPPORT | INFO_SET_SUPPORT),
    XU_FRAME_TYPE_LEN,1,
    0,FT_IVIDEO_IDR_FRAME,FT_IVIDEO_IDR_FRAME,FT_IVIDEO_IDR_FRAME,FT_IVIDEO_IDR_FRAME
};

VC_CMD_CFG VC_XU_VIDEO_CDC_CFG = {
    (CAP_GET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_LEN_CMD),
    (INFO_GET_SUPPORT),
    XU_CAMERA_DELAY_LEN,1,
    0,0,0,0,0
} ;

VC_CMD_CFG VC_XU_VIDEO_FILTER_CFG = {
    (CAP_SET_CUR_CMD | CAP_GET_CUR_CMD | CAP_GET_INFO_CMD | CAP_GET_DEF_CMD | CAP_GET_LEN_CMD),
    (INFO_GET_SUPPORT | INFO_SET_SUPPORT),
    XU_FILTER_LEN,1,
    0,0,0,0,0
} ;
*/

H264_ENCODER_VFC_CFG * usb_get_uvc_h264_cfg(void)
{
    return (H264_ENCODER_VFC_CFG *) &gsH264EncoderVFC_Cfg_Cur;
}

#endif

#if (CUSTOMER == ASU)
VC_CMD_CFG VC_XU_ASU_VERSION_CFG = {
(CAP_XU_GET_ONLY_CMD),
(INFO_GET_SUPPORT),
1,
(CMD_VALUE) 0x21,(CMD_VALUE) 0x21, //RES, DEF
(CMD_VALUE) 0x21,(CMD_VALUE) 0x21,(CMD_VALUE) 0x21 //MIN, MAX, CUR
};

VC_CMD_CFG VC_XU_ASU_LAST_ERROR_CFG = {
(CAP_XU_GET_ONLY_CMD),
(INFO_GET_SUPPORT),
1,
(CMD_VALUE) 0,(CMD_VALUE) 0, //RES, DEF
(CMD_VALUE) 0,(CMD_VALUE) 0,(CMD_VALUE) 0 //MIN, MAX, CUR
};

VC_CMD_CFG VC_XU_ASU_AF_LOCK_CFG = {
(CAP_XU_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
1,
(CMD_VALUE) 1,(CMD_VALUE) 0, //RES, DEF
(CMD_VALUE) 0,(CMD_VALUE) 1,(CMD_VALUE) 0 //MIN, MAX, CUR
};

VC_CMD_CFG VC_XU_ASU_AE_LOCK_CFG = {
(CAP_XU_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
1,
(CMD_VALUE) 1,(CMD_VALUE) 0, //RES, DEF
(CMD_VALUE) 0,(CMD_VALUE) 1,(CMD_VALUE) 0 //MIN, MAX, CUR
};

static FOCUSED_RECT m_rcCur = {0, 0, 0, 0};
static FOCUSED_RECT m_rcMax = {0, 0, 0, 0};
static FOCUSED_RECT m_rcMin = {0, 0, 1, 1};
static FOCUSED_RECT m_mappedFR;
//static MMP_USHORT m_mappedTop;//Y start, based on current width
//static MMP_USHORT m_mappedBottom;//Y end, based on current width

MMP_UBYTE m_tCAFEnable = 1;//if ASU_CAMERA_APP control AF stop, use to block other IF control AF.

VC_CMD_CFG VC_XU_ASU_FOCUS_RECT_CFG = {
(CAP_XU_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
sizeof(FOCUSED_RECT),
(CMD_VALUE) 1,(CMD_VALUE) & m_rcMin, //RES, DEF
(CMD_VALUE) & m_rcMin,(CMD_VALUE) & m_rcMax,(CMD_VALUE) & m_rcCur //MIN, MAX, CUR
};

MMP_UBYTE m_asuValidRect = 0;

#define EU2_ASU_RESULT_LEN  (0x04)
VC_CMD_CFG VC_XU_ASU_RESULT_CFG = {
(CAP_SET_CUR_CMD | CAP_GET_CUR_CMD),
(INFO_GET_SUPPORT | INFO_SET_SUPPORT),
EU2_ASU_RESULT_LEN,
0,0,0,0,0
} ;

MMP_UBYTE eu2_xu_asu_result_val[EU2_ASU_RESULT_LEN];

//#define XU_ASU_VERSION_CONTROL    (1)
//#define XU_ASU_LAST_ERROR_CONTROL (2)
//#define XU_ASU_AE_LOCK_CONTROL    (3)
//#define XU_ASU_AF_LOCK_CONTROL    (4)
//#define XU_ASU_FOCUS_RECT_CONTROL (5)

#define XU_ASU_SPECIFIC_CONTROL_SELECTOR        (0x01)
#define XU_ASU_SWITCH_CAMERA                (0x01)
#define XU_ASU_QUERY_5M_RESOLUTION_INUSE    (0x02)

extern VC_CMD_CFG CT_PANTILT_RELATIVE_CFG;

#if (CUSTOMER == ASU)
/** Config touch AE according to ASU XU
 *
 *  @pre set VC_XU_ASU_FOCUS_RECT_CFG.dwCurVal correctly.
 *  @pre set VC_XU_ASU_AE_LOCK_CFG.dwCurVal correctly.
 */
void xu_asu_config_tae(void)
{
    //FOCUSED_RECT * const pFR = (FOCUSED_RECT*)(VC_XU_ASU_FOCUS_RECT_CFG.dwCurVal);
    FOCUSED_RECT * const pFR = &m_mappedFR;
#if (ASU_CAMERA_APP_VERSION > 23)
#if 0
    //decision from ASUS-Kenny and  ISP-Yengliang, forced disable TAE temporarily 2012/10/28
    dbg_printf(0, "Force disable TAE, ");
    dbg_printf(1, "rect:%d,%d-%dx%d,", pFR->wLeft, pFR->wTop, pFR->wRight, pFR->wBottom);
    xu_asu_set_err(ASU_ERR_NOT_SUPPORTTED);
#else
    //temp process to fix tae process
    if ((m_asuValidRect) && ((MMP_UBYTE)(MMP_ULONG)VC_XU_ASU_AE_LOCK_CFG.dwCurVal == 1)) {//enable
        ISP_IF_AE_SetCustomWin(pFR->wLeft, pFR->wRight, pFR->wTop, pFR->wBottom, GetFitRange()->usInWidth);
        ISP_IF_AE_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_ON);
        dbg_printf(0, " AE_WIN_ON,");
        xu_asu_set_err(ASU_ERR_NONE);
    } else if ((m_asuValidRect) && ((MMP_UBYTE)(MMP_ULONG)VC_XU_ASU_AE_LOCK_CFG.dwCurVal == 0)) {//disable
        ISP_IF_AE_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_OFF);
        dbg_printf(0, " AE_WIN_OFF,");
        xu_asu_set_err(ASU_ERR_NONE);
    }
    else {
        dbg_printf(0, " AE_NOT_ALLOWED,");
        xu_asu_set_err(ASU_ERR_NOT_ALLOWED);
    }
#endif
#else
    //original process
    if((MMP_UBYTE) (MMP_ULONG) VC_XU_ASU_AE_LOCK_CFG.dwCurVal == 1){
        //enable
        if(m_asuValidRect){
            //ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AE, 0);
            ISP_IF_AE_SetCustomWin(pFR->wLeft, pFR->wRight, m_mappedTop, m_mappedBottom, gPCCamCurRes->res_w);
            ISP_IF_AE_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_ON);
            //ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AE, 1);
            xu_asu_set_err(ASU_ERR_NONE);
        }
        else{
            ISP_IF_AE_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_OFF);
            xu_asu_set_err(ASU_ERR_NOT_ALLOWED);
        }
    }
    else{
        ISP_IF_AE_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_OFF);
        xu_asu_set_err(ASU_ERR_NONE);
    }
#endif
}

/** Config touch AF according to ASU XU
 *
 *  @pre set VC_XU_ASU_FOCUS_RECT_CFG.dwCurVal correctly.
 *  @pre set VC_XU_ASU_AF_LOCK_CFG.dwCurVal correctly.
 */
void xu_asu_config_taf(void)
{
    //FOCUSED_RECT * const pFR = (FOCUSED_RECT*)(VC_XU_ASU_FOCUS_RECT_CFG.dwCurVal);
    FOCUSED_RECT * const pFR = &m_mappedFR;
#if (ASU_CAMERA_APP_VERSION > 23)
    //temp process to fix taf process
    if((m_asuValidRect) && ((MMP_UBYTE) (MMP_ULONG) VC_XU_ASU_AF_LOCK_CFG.dwCurVal == 1)){
        //enable AF
        ISP_IF_AF_SetCustomWin(pFR->wLeft, pFR->wRight, pFR->wTop, pFR->wBottom, GetFitRange()->usInWidth);
        ISP_IF_AF_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_ON);
        ISP_IF_AF_SetType(ISP_AF_TYPE_ONE_SHOT);
        ISP_IF_AF_Control(ISP_AF_START);
        m_tCAFEnable = 0;
        dbg_printf(1, " AF_TYPE_ONE_SHOT,");
        xu_asu_set_err(ASU_ERR_NONE);
    }
    else if((m_asuValidRect) && ((MMP_UBYTE) (MMP_ULONG) VC_XU_ASU_AF_LOCK_CFG.dwCurVal == 2)){
        //enable CAF
        ISP_IF_AF_SetCustomWin(pFR->wLeft, pFR->wRight, pFR->wTop, pFR->wBottom, GetFitRange()->usInWidth);
        ISP_IF_AF_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_ON);
        ISP_IF_AF_SetType(ISP_AF_TYPE_CONTINUOUS);
        ISP_IF_AF_Control(ISP_AF_START);
        m_tCAFEnable = 1;
        dbg_printf(1, " AF_TYPE_CONTINUOUS,");
        xu_asu_set_err(ASU_ERR_NONE);
    }
    else if((m_asuValidRect) && ((MMP_UBYTE) (MMP_ULONG) VC_XU_ASU_AF_LOCK_CFG.dwCurVal == 0)){
        //disable AF/CAF
        ISP_IF_AF_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_OFF);
        ISP_IF_AF_Control(ISP_AF_STOP);
        m_tCAFEnable = 0;
        dbg_printf(1, " AF_STOP,");
        xu_asu_set_err(ASU_ERR_NONE);
    }
    else{
        dbg_printf(1, " AF_NOT_ALLOWED,");
        xu_asu_set_err(ASU_ERR_NOT_ALLOWED);
    }
#else
    //original process
    if((MMP_UBYTE) (MMP_ULONG) VC_XU_ASU_AF_LOCK_CFG.dwCurVal == 1){
        //enable
        if(m_asuValidRect){
            ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AF, 0);
            ISP_IF_AF_SetCustomWin(pFR->wLeft, pFR->wRight, m_mappedTop, m_mappedBottom, gPCCamCurRes->res_w);
            ISP_IF_AF_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_ON);
            ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AF, 1);
            xu_asu_set_err(ASU_ERR_NONE);
        }
        else{
            ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AF, 0);
            ISP_IF_AF_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_OFF);
            ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AF, 1);
            xu_asu_set_err(ASU_ERR_NOT_ALLOWED);
        }
    }
    else{
        ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AF, 0);
        ISP_IF_AF_SetCustomWinMode(ISP_CUSTOM_WIN_MODE_OFF);
        ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AF, 1);
        xu_asu_set_err(ASU_ERR_NONE);
    }
#endif
}

/** Config touch window according to ASU XU
 *
 *  @pre set VC_XU_ASU_FOCUS_RECT_CFG.dwCurVal correctly.
 *  @warning The data is assigned anyway even if it is invalid.
 */
void xu_asu_config_twindow(void)
{
    FOCUSED_RECT * const pFR = (FOCUSED_RECT *) (VC_XU_ASU_FOCUS_RECT_CFG.dwCurVal);
    MMPF_SCALER_FIT_RANGE *pFitRange = GetFitRange();
    MMPF_SCALER_GRABCONTROL *grab;

    const STREAM_CFG * stream_cfg = usb_get_stream_cfg();
    MMPF_SCALER_PATH main_stream;

    if(stream_cfg->pipe_en & PIPE1_EN){
        main_stream = MMPF_SCALER_PATH_1;
    }
    else if(stream_cfg->pipe_en & PIPE0_EN){
        main_stream = MMPF_SCALER_PATH_0;
    }
    else{
        DBG_S(1, "[ERR] Get main stream cfg\r\n");
        return;
    }

    grab = &(MMPF_Scaler_GetCurInfo(main_stream)->grabCtl);

    //dbg_printf(3, "res %dx%d\r\n", gPCCamCurRes->res_w, gPCCamCurRes->res_h);
    //dbg_printf(3, "RC t:%d b:%d l:%d r:%d\r\n", pFR->wTop, pFR->wBottom, pFR->wLeft, pFR->wRight);

    m_asuValidRect = 0;
    if(gPCCamCurRes != NULL){
        if((pFR->wTop > gPCCamCurRes->res_h) ||
           (pFR->wBottom > gPCCamCurRes->res_h) ||
           (pFR->wLeft > gPCCamCurRes->res_w) ||
           (pFR->wRight > gPCCamCurRes->res_w) ||
           (pFR->wTop > pFR->wBottom) ||
           (pFR->wLeft > pFR->wRight)){
            xu_asu_set_err(ASU_ERR_INVALID_ARGUMENT);
        }
        else{
            if(gPCCamCurRes->res_h){
                m_mappedFR.wTop = (pFR->wTop * grab->usScaleM + grab->usScaleN - 1) /
                                  grab->usScaleN +
                                  grab->usStartY -
                                  1;
                m_mappedFR.wBottom = (pFR->wBottom * grab->usScaleM + grab->usScaleN - 1) /
                                     grab->usScaleN +
                                     grab->usStartY -
                                     1;
                m_mappedFR.wLeft = (pFR->wLeft * grab->usScaleM + grab->usScaleN - 1) /
                                   grab->usScaleN +
                                   grab->usStartX -
                                   1;
                m_mappedFR.wRight = (pFR->wRight * grab->usScaleM + grab->usScaleN / -1) /
                                    grab->usScaleN +
                                    grab->usStartX -
                                    1;

                //dbg_printf(3, "mapped RC t:%d b:%d l:%d r:%d\r\n", m_mappedFR.wTop, m_mappedFR.wBottom, m_mappedFR.wLeft, m_mappedFR.wRight);

                //assume the width of sensor input is always bigger than the height.
                //dbg_printf(3, "sensor input %dx%d\r\n", pFitRange->usInWidth, pFitRange->usInHeight);
                m_mappedFR.wTop = (m_mappedFR.wTop * pFitRange->usInWidth + pFitRange->usInHeight - 1) /
                                  pFitRange->usInHeight;
                m_mappedFR.wBottom = (m_mappedFR.wBottom * pFitRange->usInWidth + pFitRange->usInHeight - 1) /
                                     pFitRange->usInHeight;
                //dbg_printf(3, "mapped RC t:%d b:%d l:%d r:%d\r\n", m_mappedFR.wTop, m_mappedFR.wBottom, m_mappedFR.wLeft, m_mappedFR.wRight);
                m_asuValidRect = 1;
            }
            else{
                xu_asu_set_err(ASU_ERR_NOT_ALLOWED);
            }
        }
    }
    else{
        xu_asu_set_err(ASU_ERR_NOT_ALLOWED);
    }
}
#endif

void xu_asu_set_err(const MMP_UBYTE err)
{
    VC_XU_ASU_LAST_ERROR_CFG.dwCurVal = (CMD_VALUE) err;
#if UVC_IT_BITMAP & (1 << 12)
    CT_PANTILT_RELATIVE_CFG.dwCurVal = (CMD_VALUE)
                                       (((MMP_ULONG) CT_PANTILT_RELATIVE_CFG.dwCurVal & 0x00FF0000) | (err << 16));
#endif
}

__inline MMP_UBYTE xu_asu_get_err(void)
{
    return (MMP_UBYTE) (MMP_ULONG) VC_XU_ASU_LAST_ERROR_CFG.dwCurVal;
}
#endif

//customer commands
void usb_vc_eu2_cs(MMP_UBYTE req)
{
    MMP_UBYTE cs;
    //    volatile MMP_UBYTE *USB_REG_BASE_B = (volatile MMP_UBYTE *) USB_CTL_BASE_ADDR;
    //    MMP_UBYTE i;
    cs = (UsbRequestPayload_wValue >> 8);
    UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);
    switch(cs){
#if 0 //USB_UVC_H264==1
case XU_ENCODER_VIDEO_FORMAT_CONTROL:
    usb_vc_cmd_cfg(req,&VC_XU_VIDEO_FORMAT_CFG,(MMP_ULONG)&gsH264EncoderVFC_Cfg_Cur);
    break ;
case XU_ENCODER_CONFIGURATION_CONTROL:
    usb_vc_cmd_cfg(req,&VC_XU_VIDEO_CONFIG_CFG,(MMP_ULONG)&gsH264EncoderCC_Cfg_Cur);
    break ;
case XU_RATE_CONTROL:
    usb_vc_cmd_cfg(req,&VC_XU_VIDEO_RATECTL_CFG,(MMP_ULONG)&gsH264EncoderRC_Cfg_Cur);
    break;
case XU_FRAME_TYPE_CONTROL:
    usb_vc_cmd_cfg(req,&VC_XU_VIDEO_FRAMETYPE_CFG,gbH264EncoderFTC_Cfg);
    break;
case XU_CAMERA_DELAY_CONTROL:
    usb_vc_cmd_cfg(req,&VC_XU_VIDEO_CDC_CFG,gsH264EncoderCDC_Cfg);
    break;
case XU_FILTER_CONTROL:
{
    MMP_USHORT filterControl ;
    filterControl = gsH264EncoderFilter_Cfg.bTemporalFilterStrength | (gsH264EncoderFilter_Cfg.bSpatialFilterStrength<<8);
    usb_vc_cmd_cfg(req,&VC_XU_VIDEO_FILTER_CFG,filterControl);
    break ;
}
#endif

#if (CUSTOMER == ASU)
#if 0
    case XU_ASU_VERSION_CONTROL:
        usb_vc_cmd_cfg(req,&VC_XU_ASU_VERSION_CFG,VC_XU_ASU_VERSION_CFG.dwCurVal);
        break;
    case XU_ASU_LAST_ERROR_CONTROL:
        usb_vc_cmd_cfg(req,&VC_XU_ASU_LAST_ERROR_CFG,VC_XU_ASU_LAST_ERROR_CFG.dwCurVal);
        break;
    case XU_ASU_AE_LOCK_CONTROL:
        usb_vc_cmd_cfg(req,&VC_XU_ASU_AE_LOCK_CFG,VC_XU_ASU_AE_LOCK_CFG.dwCurVal);
        break;
    case XU_ASU_AF_LOCK_CONTROL:
        usb_vc_cmd_cfg(req,&VC_XU_ASU_AF_LOCK_CFG,VC_XU_ASU_AF_LOCK_CFG.dwCurVal);
        break;
    case XU_ASU_FOCUS_RECT_CONTROL:
        usb_vc_cmd_cfg(req,&VC_XU_ASU_FOCUS_RECT_CFG, VC_XU_ASU_FOCUS_RECT_CFG.dwCurVal);
        break;
#else
    case XU_ASU_SPECIFIC_CONTROL_SELECTOR:
        usb_vc_cmd_cfg(req,&VC_XU_ASU_RESULT_CFG, (CMD_VALUE)eu2_xu_asu_result_val);
        break;
#endif
#endif
        //case XU_CONTROL_UNDEFINED:
    default:
        // un-support
        usb_vc_stall(CONTROL_INVALID_CONTROL);
        break;
    }
}

void usb_vc_eu2_cs_out(void)
{
    MMP_UBYTE cs,len;
    MMP_UBYTE err = 0;

    cs = (UsbRequestPayload_wValue >> 8);
    len = UsbRequestPayload_wLength;
    switch(cs){
#if 0//USB_UVC_H264==1
    case XU_ENCODER_VIDEO_FORMAT_CONTROL:  // 3.4.1.1 Encoder Video Format Control
        USBOutData = 0;
        ptr = (MMP_UBYTE *)&gsH264EncoderVFC_Cfg_Cur ;
        for(i=0;i<XU_ENCODER_VIDEO_FORMAT_LEN;i++) {
            ptr[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B ;
        }
        // DO something here...


        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;
    case XU_ENCODER_CONFIGURATION_CONTROL: // 3.4.1.2 Encoder Configuration Control
        USBOutData = 0;
        ptr = (MMP_UBYTE *)&gsH264EncoderCC_Cfg_Cur ;
        for(i=0;i<XU_ENCODER_CONFIGURATION_LEN;i++) {
            ptr[i] =  pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B ;
        }
        // Do something here

        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;
    case XU_RATE_CONTROL:                  // 3.4.1.3 Rate Control
        USBOutData = 0;
        ptr = (MMP_UBYTE *)&gsH264EncoderRC_Cfg_Cur;
        for(i=0;i<XU_RATE_CONTROL_LEN;i++) {
            ptr[i] = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B ;
        }
        // Do something here
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;
    case XU_FRAME_TYPE_CONTROL:            // 3.4.1.4 Frame Type Control
        USBOutData = 0;
        gbH264EncoderFTC_Cfg = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B ;
        USBInPhase = SET_CUR_CMD;
        // Do something here
        usb_ep0_null_in();
        break;
    case XU_CAMERA_DELAY_CONTROL:          // 3.4.1.5 Camera Delay Control
        USBOutData = 0;
        gsH264EncoderCDC_Cfg  = (MMP_USHORT)pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B     ;
        gsH264EncoderCDC_Cfg |= (MMP_USHORT)pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B << 8;
        // Do something here
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break;
    case XU_FILTER_CONTROL:                 // Filter Delay Control
        USBOutData = 0;
        gsH264EncoderFilter_Cfg.bTemporalFilterStrength = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B ;
        gsH264EncoderFilter_Cfg.bSpatialFilterStrength  = pUSB_CTL->USB_FIFO_EP[0x0].FIFO_B ;
        // Do something here
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
        break ;
#endif
#if (CUSTOMER == ASU)
#if 0
    case XU_ASU_AE_LOCK_CONTROL:
        usb_vc_get_ep0_data((MMP_UBYTE*)&VC_XU_ASU_AE_LOCK_CFG.dwCurVal);
        xu_asu_config_tae();
        break;
    case XU_ASU_AF_LOCK_CONTROL:
        usb_vc_get_ep0_data((MMP_UBYTE*)&VC_XU_ASU_AF_LOCK_CFG.dwCurVal);
        xu_asu_config_taf();
        break;
    case XU_ASU_FOCUS_RECT_CONTROL:
        usb_vc_get_ep0_data((MMP_UBYTE*)VC_XU_ASU_FOCUS_RECT_CFG.dwCurVal);
        xu_asu_config_twindow();
        break;
#else
    case XU_ASU_SPECIFIC_CONTROL_SELECTOR:
        {
            usb_vc_get_ep0_data(eu2_xu_asu_result_val);

            switch(eu2_xu_asu_result_val[2]) {
            case XU_ASU_SWITCH_CAMERA:
                {
                    if((eu2_xu_asu_result_val[0] == XU_ASU_SPECIFIC_CONTROL_SELECTOR)
                       && (((eu2_xu_asu_result_val[1] == SET_CUR_CMD) && (eu2_xu_asu_result_val[3] < TOTAL_SENSOR_NUMBER))
                            ||(eu2_xu_asu_result_val[1] == GET_CUR_CMD))) {
#if SUPPORT_SWITCH_CAMERA
                        if(eu2_xu_asu_result_val[1] == GET_CUR_CMD) {
                            eu2_xu_asu_result_val[1] = gbSwitchSensor;
                            eu2_xu_asu_result_val[0] = EU_ISP_CMD_OK;
                        } else if(eu2_xu_asu_result_val[1]==SET_CUR_CMD) {
                            if((gbSwitchSensor != eu2_xu_asu_result_val[3]) ) {
                                gbSwitchSensor = eu2_xu_asu_result_val[3];

                                MMPF_Sensor_Set3AState(MMPF_SENSOR_3A_RESET);//sensor change! for gsSensorFunction->MMPF_Sensor_InitializeISP()==>ISP_IF_LIB_Init()
                                MMPF_Sensor_SetBufferSize(0);

                                //dbg_printf(0,"1.disconnect, ");
                                usb_sw_enum();
                                //dbg_printf(0,"2.re-connect!");
                            }
                            eu2_xu_asu_result_val[1] = gbSwitchSensor;
                            eu2_xu_asu_result_val[0] = EU_ISP_CMD_OK;
                        } else {
                            dbg_printf(1,"  Should be Never Happen\r\n");
                            eu2_xu_asu_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                        }
#else
                        dbg_printf(1,"  Funcrtion-less!(SUPPORT_SWITCH_CAMERA=0)\r\n");
                        eu2_xu_asu_result_val[0] = EU_ISP_CMD_OK;
#endif//SUPPORT_SWITCH_CAMERA
                    } else {
                        dbg_printf(1,"!#%d, CMD NOT SUPPORT!\r\n", __LINE__);
                        eu2_xu_asu_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    }
                }
                break;
            case XU_ASU_QUERY_5M_RESOLUTION_INUSE:
                {
                    if((eu2_xu_asu_result_val[0] == XU_ASU_SPECIFIC_CONTROL_SELECTOR) && (eu2_xu_asu_result_val[1] == GET_CUR_CMD)) {
                        MMP_UBYTE bIsCurrentResolution5M;

                        switch(gbCurFormatIndex)
                        {
                        case YUY2_FORMAT_INDEX:
                            bIsCurrentResolution5M = (yuy2_frame_index_to_pcam(gbCurFrameIndex)==PCCAM_2592_1944)?1:0;
                            break;
                        case MJPEG_FORMAT_INDEX:
                            bIsCurrentResolution5M = (mjpg_frame_index_to_pcam(gbCurFrameIndex)==PCCAM_2592_1944)?1:0;
                            break;
                        default:
                            bIsCurrentResolution5M = 0;
                        }

#if SUPPORT_SWITCH_CAMERA
                        eu2_xu_asu_result_val[1] = ((m_bVidRecdPreviewStatus == MMP_TRUE)&&(gbSwitchSensor==1)&&(bIsCurrentResolution5M));//5M preview
#else
                        eu2_xu_asu_result_val[1] = ((m_bVidRecdPreviewStatus == MMP_TRUE)&&(gbCurrentSensor==1)&&(bIsCurrentResolution5M));//5M preview
#endif
                        eu2_xu_asu_result_val[0] = EU_ISP_CMD_OK;
                    } else {
                        dbg_printf(1,"!#%d, CMD NOT SUPPORT!\r\n", __LINE__);
                        eu2_xu_asu_result_val[0] = EU_ISP_CMD_NOT_SUPPORT;
                    }
                }
                break;
            default:
                dbg_printf(1,"!#%d, WRONG PARAMETER!\r\n", __LINE__);
                eu2_xu_asu_result_val[2] = 0xFF;
            }//end of switch(eu2_xu_asu_result_val[0])
        }//end of case XU_ASU_SPECIFIC_CONTROL_SELECTOR
        break;
#endif
#endif
        //case XU_CONTROL_UNDEFINED:
    default:
        // impossible flow
        err = 1;
        break;
    }

    if(!err){
        USBInPhase = SET_CUR_CMD;
        usb_ep0_null_in();
    }
}

#if SKYPE_UVC_H264

//UVC1.1
void usb_vc_eu3_cs(MMP_UBYTE req)
{
    MMP_UBYTE cs;
    //    MMP_USHORT i;
    //    volatile MMP_UBYTE *USB_REG_BASE_B = (volatile MMP_UBYTE *) USB_REG_BASE_ADDR;

    cs = (UsbRequestPayload_wValue >> 8);

#if 0
    RTNA_DBG_Str(0, "eu3_cs()\r\n");
#endif

    UsbWriteEp0CSR(SET_EP0_SERVICED_RXPKTRDY);

    switch(cs){
#if SKYPE_UVC_H264==1
    case UVCX_VIDEO_CONFIG_PROBE:
        usb_vc_cmd_cfg(req, &UVCX_VIDEO_CONFIG_PROBE_CFG, (CMD_VALUE) & gsUVCXVideoConfigProbe_Cur);
        //RTNA_DBG_Str(3, "==UVCX_VIDEO_CONFIG_PROBE==\r\n");
        break ;
    case UVCX_VIDEO_CONFIG_COMMIT:
        usb_vc_cmd_cfg(req, &UVCX_VIDEO_CONFIG_COMMIT_CFG, (CMD_VALUE) & gsCurH264Config);
        //RTNA_DBG_Str(3, "==UVCX_VIDEO_CONFIG_COMMIT==\r\n");
        break ;

    case UVCX_CONTROL_MODE:
        usb_vc_cmd_cfg(req, &UVCX_CONTROL_MODE_CFG, (CMD_VALUE) 0x010000);
        break ;
        /*
            case UVCX_TEMPORAL_SCALE_MODE:
                usb_vc_cmd_cfg(req,&UVCX_TEMPORAL_SCALE_MODE_CFG,gbUVCXTemporalScaleMode);
                break ;
            case UVCX_SPATIAL_SCALE_MODE:
                usb_vc_cmd_cfg(req,&UVCX_SPATIAL_SCALE_MODE_CFG,gbUVCXSpatialScaleMode);
                break;
            case UVCX_SNR_SCALE_MODE:
                usb_vc_cmd_cfg(req,&UVCX_SNR_SCALE_MODE_CFG,gbUVCXSNRScaleMode);
                break;
        */
    case UVCX_PICTURE_TYPE_CONTROL:
        usb_vc_cmd_cfg(req, &UVCX_PICTURE_TYPE_CONTROL_CFG, ((CMD_VALUE) (gsUVCXPictureTypeControl.wPicType << 16)));
        break;
    case UVCX_VERSION:
        usb_vc_cmd_cfg(req, &UVCX_VERSION_CFG, (CMD_VALUE) gsUVCXVersion);
        //RTNA_DBG_Str(3, "==UVCX_VERSION==\r\n");
        break;

    case UVCX_ENCODER_RESET:
        usb_vc_cmd_cfg(req, &UVCX_ENCODER_RESET_CFG, 0x0000);
        break;

    case UVCX_FRAMERATE_CONFIG:
        usb_vc_cmd_cfg(req, &UVCX_FRAMERATE_CONFIG_CFG, (CMD_VALUE) & gsUVCXFrameRateConfig);
        break;

    case UVCX_VIDEO_ADVANCE_CONFIG:
        usb_vc_cmd_cfg(req, &UVCX_VIDEO_ADVANCE_CONFIG_CFG, (CMD_VALUE) & gsUVCXAdvConfig);
        break;

    case UVCX_BITRATE_LAYERS:
        usb_vc_cmd_cfg(req, &UVCX_BITRATE_CFG, (CMD_VALUE) & gsUVCXBitRateLayers);
        break;

    case UVCX_QP_STEPS_LAYERS:
        usb_vc_cmd_cfg(req, &UVCX_QP_STEPS_SIZE_CFG, (CMD_VALUE) & gsUVCXQPStepSize);
        break;

#endif
        //case XU_CONTROL_UNDEFINED:
    default:
        // un-support
        //dbg_printf(1, "unknown skype 1.1 cs %d", cs);
        usb_vc_stall(CONTROL_INVALID_CONTROL);
        break;
    }
}

#endif
#if SKYPE_UVC_H264
#if 1
void uvcx_print_uvc11_probe(char *const str, UVCX_VIDEO_CONFIG *const probe)
{
    RTNA_DBG_Str3(str);
    dbg_printf(1, " ** bStreamMuxOption = x%02X\r\n", probe->bStreamMuxOption);
    dbg_printf(1, " ** %dx%d  dwFrameInterval:%d\r\n", probe->wWidth, probe->wHeight, probe->dwFrameInterval);
    dbg_printf(1, " ** dwBitrate %d\r\n ** bTimestamp %d\r\n", probe->dwBitRate, probe->bTimestamp);
}
#else
#define uvcx_print_uvc11_probe(str,probe)
#endif

void usb_vc_eu3_cs_out(void)//UVC 1.1 H.264 payload
{
    MMP_UBYTE cs,len;
    MMP_UBYTE *tmpptrb;
    MMP_BOOL IsPreviewEnable ;
    SKYPE_RES_TYPE_CFG *cur_res;

    cs = (UsbRequestPayload_wValue >> 8);
    len = UsbRequestPayload_wLength;

#if 0
    RTNA_DBG_Str(0, "usb_vc_eu3_cs_out()\r\n");
    RTNA_DBG_Str(0, "cs = ");
    RTNA_DBG_Byte(0, cs);
    RTNA_DBG_Str(0, " : len = ");
    RTNA_DBG_Byte(0, len);
    RTNA_DBG_Str(0, "\r\n");
#endif

    switch(cs){
    case UVCX_VIDEO_CONFIG_PROBE:
        // 3,3.1 UVCX_VIDEO_CONFIG_PROBE
         {
            USBOutData = 0;
            tmpptrb = (MMP_UBYTE *) &video_probe ;
            USB_GET_FIFO_DATA(MMPF_USB_EP0, len, tmpptrb, UVCX_VIDEO_CONFIG_PROBE_LEN);

            if((video_probe.bStreamMuxOption == 0) || ((video_probe.bStreamMuxOption & 0x0F) > 0x09)){
                // un-support
                RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_PROBE bStreamMuxOption error\r\n");
                goto video_config_probe_exit;
            }
            /*
                    if((video_probe.wWidth > 1280) || (video_probe.wHeight > 720) || (video_probe.wWidth < 160) || (video_probe.wHeight < 90)){
                        // un-support
                        RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_PROBE wWidth/wHeight error\r\n");
                        goto video_config_probe_exit;
                    }
            */
            if(video_probe.dwFrameInterval < 330000){
                // un-support
                //RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_PROBE dwFrameInterval error\r\n");
                //goto video_config_probe_exit;
                video_probe.dwFrameInterval = 330000;
            }
            else if(video_probe.dwFrameInterval > 2000000){
                video_probe.dwFrameInterval = 2000000;
            }

            if(video_probe.bStreamMuxOption & DUAL_AUX_H264){
                if(video_probe.bStreamMuxOption & (DUAL_AUX_YUY2 | DUAL_AUX_NV12)){
                    // un-support
                    RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_PROBE bStreamMuxOption2 error\r\n");
                    goto video_config_probe_exit;
                }

                if(video_probe.dwBitRate < 5000){
                    // un-support
                    //RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_PROBE dwBitRate error\r\n");
                    //goto video_config_probe_exit;
                    video_probe.dwBitRate = 5000;
                }

                if((video_probe.wProfile != 0x4240)){
                    video_probe.wProfile = 0x4240;
                }

                if((video_probe.bEntropyCABAC > 0)){
                    video_probe.bEntropyCABAC = 0;
                }

                cur_res = SearchSkypeMainStreamRes(video_probe.wWidth, video_probe.wHeight);
            }
            else if(video_probe.bStreamMuxOption & DUAL_AUX_YUY2){
                if(video_probe.bStreamMuxOption & (DUAL_AUX_H264 | DUAL_AUX_NV12)){
                    // un-support
                    RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_PROBE bStreamMuxOption2 error\r\n");
                    goto video_config_probe_exit;
                }

                cur_res = SearchSkypePreviewStreamRes(video_probe.wWidth, video_probe.wHeight);
            }

            video_probe.wWidth = cur_res->res_w;
            video_probe.wHeight = cur_res->res_h;

            UVCX_SetCurVideoProbeConfig((UVCX_VIDEO_CONFIG *) &video_probe);

#if 1
            uvcx_print_uvc11_probe("UVCX_VIDEO_CONFIG_PROBE:\r\n", &gsUVCXVideoConfigProbe_Cur);
#else
            RTNA_DBG_Str3("UVCX_VIDEO_CONFIG_PROBE:\r\n");

            RTNA_DBG_Str(0, " ** bStreamMuxOption = ");
            RTNA_DBG_Byte(0, gsUVCXVideoConfigProbe_Cur.bStreamMuxOption);
            RTNA_DBG_Str(0, " **\r\n");
            RTNA_DBG_Str(0, " ** wWidth = ");
            MMPF_DBG_Int(gsUVCXVideoConfigProbe_Cur.wWidth, -4);
            RTNA_DBG_Str(0, "  : ");
            RTNA_DBG_Str(0, " wHeight = ");
            MMPF_DBG_Int(gsUVCXVideoConfigProbe_Cur.wHeight, -4);
            RTNA_DBG_Str(0, " **\r\n");
            RTNA_DBG_Str(0, " ** dwFrameInterval = ");
            MMPF_DBG_Int(gsUVCXVideoConfigProbe_Cur.dwFrameInterval, -7);
            RTNA_DBG_Str(0, " **\r\n");
            RTNA_DBG_Str(0, " ** dwBitrate = ");
            MMPF_DBG_Int(gsUVCXVideoConfigProbe_Cur.dwBitRate, -8);
            RTNA_DBG_Str(0, " **\r\n");
            RTNA_DBG_Str(0, " ** wIFramePeriod = ");
            MMPF_DBG_Int(gsUVCXVideoConfigProbe_Cur.wIFramePeriod, -6);
            RTNA_DBG_Str(0, " **\r\n");
            RTNA_DBG_Str(0, " ** bTimestamp = ");
            MMPF_DBG_Int(gsUVCXVideoConfigProbe_Cur.bTimestamp, -2);
            RTNA_DBG_Str(0, " **\r\n");
#endif

            video_config_probe_exit : USBInPhase = SET_CUR_CMD;
            usb_ep0_null_in();
            break ;
        }
    case UVCX_VIDEO_CONFIG_COMMIT:
        // 3,3.2 UVCX_VIDEO_CONFIG_COMMIT
         {
            USBOutData = 0;
            tmpptrb = (MMP_UBYTE *) &video_probe ;
            USB_GET_FIFO_DATA(MMPF_USB_EP0, len, tmpptrb, UVCX_VIDEO_CONFIG_COMMIT_LEN);

            if((video_probe.bStreamMuxOption == 0) || ((video_probe.bStreamMuxOption & 0x0F) > 0x09)){
                // un-support
                RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_COMMIT bStreamMuxOption error\r\n");
                goto video_config_commit_exit;
            }
            /*
                    if((video_probe.wWidth > 1280) || (video_probe.wHeight > 720) || (video_probe.wWidth < 160) || (video_probe.wHeight < 90)){
                        // un-support
                        RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_COMMIT wWidth/wHeight error\r\n");
                        goto video_config_commit_exit;
                    }
            */
            if(video_probe.dwFrameInterval < 330000){
                // un-support
                //RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_COMMIT dwFrameInterval error\r\n");
                //goto video_config_commit_exit;
                video_probe.dwFrameInterval = 330000;
            }
            else if(video_probe.dwFrameInterval > 2000000){
                video_probe.dwFrameInterval = 2000000;
            }

            if(video_probe.bStreamMuxOption & DUAL_AUX_H264){
                if(video_probe.bStreamMuxOption & (DUAL_AUX_YUY2 | DUAL_AUX_NV12)){
                    // un-support
                    RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_COMMIT bStreamMuxOption2 error\r\n");
                    goto video_config_commit_exit;
                }

                if(video_probe.dwBitRate < 5000){
                    // un-support
                    //RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_COMMIT dwBitRate error\r\n");
                    //goto video_config_commit_exit;
                    video_probe.dwBitRate = 5000;
                }

                if((video_probe.wProfile != 0x4240)){
                    // un-support
                    RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_COMMIT wProfile error\r\n");
                    goto video_config_commit_exit;
                }

                if((video_probe.bEntropyCABAC > 0)){
                    // un-support
                    RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_COMMIT bEntropyCABAC error\r\n");
                    goto video_config_commit_exit;
                }

                UVCX_CommitH264Config((UVCX_VIDEO_CONFIG *) &video_probe);

#if 1
                uvcx_print_uvc11_probe("UVCX_VIDEO_CONFIG_COMMIT (gsCurH264Config):\r\n", &gsCurH264Config);
#else
                RTNA_DBG_Str3("UVCX_VIDEO_CONFIG_COMMIT (gsCurH264Config):\r\n");

                RTNA_DBG_Str(0, " ** bStreamMuxOption = ");
                RTNA_DBG_Byte(0, gsCurH264Config.bStreamMuxOption);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** wWidth = ");
                MMPF_DBG_Int(gsCurH264Config.wWidth, -4);
                RTNA_DBG_Str(0, "  : ");
                RTNA_DBG_Str(0, " wHeight = ");
                MMPF_DBG_Int(gsCurH264Config.wHeight, -4);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** dwFrameInterval = ");
                MMPF_DBG_Int(gsCurH264Config.dwFrameInterval, -7);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** dwBitrate = ");
                MMPF_DBG_Int(gsCurH264Config.dwBitRate, -8);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** wIFramePeriod = ");
                MMPF_DBG_Int(gsCurH264Config.wIFramePeriod, -6);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** bTimestamp = ");
                MMPF_DBG_Int(gsCurH264Config.bTimestamp, -2);
                RTNA_DBG_Str(0, " **\r\n");
#endif
            }
            else if(video_probe.bStreamMuxOption & DUAL_AUX_YUY2){
                if(video_probe.bStreamMuxOption & (DUAL_AUX_H264 | DUAL_AUX_NV12)){
                    // un-support
                    RTNA_DBG_Str(0, " ** UVCX_VIDEO_CONFIG_COMMIT bStreamMuxOption2 error\r\n");
                    goto video_config_commit_exit;
                }

                UVCX_CommitPreviewConfig((UVCX_VIDEO_CONFIG *) &video_probe);

#if 1
                uvcx_print_uvc11_probe("UVCX_VIDEO_CONFIG_COMMIT (gsCurPreviewConfig):\r\n", &gsCurPreviewConfig);
#else
                RTNA_DBG_Str3("UVCX_VIDEO_CONFIG_COMMIT (gsCurPreviewConfig):\r\n");

                RTNA_DBG_Str(0, " ** bStreamMuxOption = ");
                RTNA_DBG_Byte(0, gsCurPreviewConfig.bStreamMuxOption);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** wWidth = ");
                MMPF_DBG_Int(gsCurPreviewConfig.wWidth, -4);
                RTNA_DBG_Str(0, "  : ");
                RTNA_DBG_Str(0, " wHeight = ");
                MMPF_DBG_Int(gsCurPreviewConfig.wHeight, -4);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** dwFrameInterval = ");
                MMPF_DBG_Int(gsCurPreviewConfig.dwFrameInterval, -7);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** dwBitrate = ");
                MMPF_DBG_Int(gsCurPreviewConfig.dwBitRate, -8);
                RTNA_DBG_Str(0, " **\r\n");
                RTNA_DBG_Str(0, " ** bTimestamp = ");
                MMPF_DBG_Int(gsCurPreviewConfig.bTimestamp, -2);
                RTNA_DBG_Str(0, " **\r\n");
#endif
            }


video_config_commit_exit:
        USBInPhase = SET_CUR_CMD;
            usb_ep0_null_in();
            break ;
        }
        /*
            case UVCX_CONTROL_MODE:  // 3.3.3 Encoder Video Format Control
            {
                USBOutData = 0;
                USB_GET_FIFO_DATA(MMPF_USB_EP0,len,&tmp, sizeof(tmp) );
                if( (tmp <= RESERVED_H264) || (tmp >= NUM_H264_CTLMODE) ) {
                    UsbWriteEp0CSR(SET_EP0_SENDSTALL | SET_EP0_SERVICED_RXPKTRDY);
                     gbVCERRCode=CONTROL_OUT_OF_RANGE ;
                     break ;
                } else {
        //            UVCX_SetH264ControlMode((H264ControlMode)tmp);
                }
                USBInPhase = SET_CUR_CMD;
                usb_ep0_null_in();
                break;
            }
            case UVCX_TEMPORAL_SCALE_MODE: // 3.3.4 UVCX_TEMPORAL_SCALE_MODE
            {
                USBOutData = 0;
                // Do something here
                USB_GET_FIFO_DATA(MMPF_USB_EP0,len,&tmp, sizeof(tmp) );
                if( (tmp < ONE_LAYER_H264) || (tmp > SEVEN_LAYER_H264) ) {
                    UsbWriteEp0CSR(SET_EP0_SENDSTALL | SET_EP0_SERVICED_RXPKTRDY);
                     gbVCERRCode=CONTROL_OUT_OF_RANGE;
                     break ;
        }
        else {
        //            UVCX_SetH264TemporalScaleMode((H264TemporalScaleMode)tmp) ;
                }
                USBInPhase = SET_CUR_CMD;
                usb_ep0_null_in();
                break;
            }
            case UVCX_SPATIAL_SCALE_MODE:        // 3.3.5 UVCX_SPATIAL_SCALE_MODE
            {
                USBOutData = 0;
                USB_GET_FIFO_DATA(MMPF_USB_EP0,len,&tmp, sizeof(tmp) );
                if( (tmp < ONE_SPATIAL_LAYER) || (tmp > EIGHT_SPATIAL_LAYER) ) {
                    UsbWriteEp0CSR(SET_EP0_SENDSTALL | SET_EP0_SERVICED_RXPKTRDY);
                     gbVCERRCode=CONTROL_OUT_OF_RANGE;
                     break ;
        }
        else {
        //            UVCX_SetH264SpatialScaleMode((H264SpatialScaleMode)tmp) ;
                }
                USBInPhase = SET_CUR_CMD;
                usb_ep0_null_in();
                break;
            }
            case UVCX_SNR_SCALE_MODE:            // 3.3.6 UVCX_SNR_SCALE_MODE
            {
                USBOutData = 0;
                USB_GET_FIFO_DATA(MMPF_USB_EP0,len,&tmp, sizeof(tmp) );
                if( (tmp < ONE_SPATIAL_LAYER) || (tmp > ALLMOMODES) ) {
                    UsbWriteEp0CSR(SET_EP0_SENDSTALL | SET_EP0_SERVICED_RXPKTRDY);
                     gbVCERRCode=CONTROL_OUT_OF_RANGE;
                     break ;
                } else {
        //            UVCX_SetH264SNRScaleMode((H264SNRScaleMode)tmp) ;
                }
                usb_ep0_null_in();
                break;
            }
        */
    case UVCX_PICTURE_TYPE_CONTROL:
        // 3,3.9 UVCX_PICTURE_TYPE_CONTROL
         {
            tmpptrb = (MMP_UBYTE *) &pict_type ;
            USBOutData = 0;
            USB_GET_FIFO_DATA(MMPF_USB_EP0, len, tmpptrb, UVCX_PIC_TYPE_LEN);
            if((pict_type.wPicType != PIC_IDR_FRAME) && (pict_type.wPicType != PIC_IDR_WITH_NEW_SPSPPS)){
                // un-support
                RTNA_DBG_Str(0, " ** UVCX_PICTURE_TYPE_CONTROL error\r\n");
                goto uvcx_picture_type_control_exit;
            }

            //      UVCX_SetH264PictureTypeCtl(pict_type.wPicType);

            USB_ForceH264IDRFrame();  //Set IDR frame

            RTNA_DBG_Str(3, "UVCX IDR Frame = ");
            RTNA_DBG_Short(3, pict_type.wPicType);
            RTNA_DBG_Str(3, "\r\n");

            uvcx_picture_type_control_exit:

            USBInPhase = SET_CUR_CMD;
            usb_ep0_null_in();
            break ;
        }
        /*
            case UVCX_VERSION:                  // 3,3.10 UVCX_VERSION
            {
                MMP_USHORT ver;
                USBOutData = 0;
                USB_GET_FIFO_DATA(MMPF_USB_EP0,len,(MMP_UBYTE *)&ver, 2);
                gsUVCXVersion = ver;
                RTNA_DBG_Str(0,"gsUVCXVersion = ");
                RTNA_DBG_Short(0,gsUVCXVersion);
                RTNA_DBG_Str(0,"\r\n");
                USBInPhase = SET_CUR_CMD;
                usb_ep0_null_in();
                break ;
            }
        */
        /*
            case UVCX_CROP_CONFIG:
            {
                MMP_UBYTE crop[UVCX_CROP_CONFIG_LEN] ;
                USBOutData = 0;
                USB_GET_FIFO_DATA(MMPF_USB_EP0,len,crop, UVCX_CROP_CONFIG_LEN);
        //        UVCX_SetH264CropConfig( (UVCX_CropConfig *)crop);
                USBInPhase = SET_CUR_CMD;
                usb_ep0_null_in();
                break ;
            }
        */
    case UVCX_FRAMERATE_CONFIG:
        // 3,3.12 UVCX_FRAMERATE_CONFIG
         {
            tmpptrb = (MMP_UBYTE *) &fr;
            USBOutData = 0;
            USB_GET_FIFO_DATA(MMPF_USB_EP0, len, tmpptrb, UVCX_FRAMERATE_LEN);

            if(fr.dwFrameInterval < 330000){
                fr.dwFrameInterval = 330000;
                // un-support
                //RTNA_DBG_Str(0, " ** UVCX_FRAMERATE_CONFIG error\r\n");
                //goto uvcx_framerate_config_exit;
            }
            else if(fr.dwFrameInterval > 2000000){
                fr.dwFrameInterval = 2000000;
            }

            gsUVCXFrameRateConfig.wLayerID = fr.wLayerID;
            gsUVCXFrameRateConfig.dwFrameInterval = fr.dwFrameInterval;

            UVCX_SetH264FrameRate(0, fr.dwFrameInterval);

            //uvcx_framerate_config_exit:

            USBInPhase = SET_CUR_CMD;
            usb_ep0_null_in();
            break ;
        }
        /*
            case UVCX_VIDEO_ADVANCE_CONFIG:         // 3.3.13 UVCX_VIDEO_ADVANCE_CONFIG
            {
                MMP_UBYTE advcfg[UVCX_ADVCONFIG_LEN];
                USBOutData = 0 ;
                USB_GET_FIFO_DATA(MMPF_USB_EP0,len,advcfg, UVCX_ADVCONFIG_LEN);
        //        UVCX_SetH264AdvConfig( (UVCX_AdvConfig *)advcfg ) ;
                USBInPhase = SET_CUR_CMD;
                usb_ep0_null_in();
                break;
            }
        */
    case UVCX_BITRATE_LAYERS:
        // 3,3.14 UVCX_BITRATE_LAYERS
         {
        tmpptrb = (MMP_UBYTE *)&gsUVCXBitRateLayers ;
            USBOutData = 0;
            USB_GET_FIFO_DATA(MMPF_USB_EP0, len, tmpptrb, UVCX_BITRATE_LEN);

        if(gsUVCXBitRateLayers.dwAverageBitrate < 5000){
            gsUVCXBitRateLayers.dwAverageBitrate = 5000;
                //goto uvcx_bitrate_layers_exit;
            }

        gsUVCXBitRateLayers.wLayerID = gsUVCXBitRateLayers.wLayerID;
        gsUVCXBitRateLayers.dwPeakBitrate = gsUVCXBitRateLayers.dwPeakBitrate;
        gsUVCXBitRateLayers.dwAverageBitrate = gsUVCXBitRateLayers.dwAverageBitrate;

            //RTNA_DBG_Str(3, "  ** dwPeakBitrate = ");
            //MMPF_DBG_Int(gsUVCXBitRateLayers.dwPeakBitrate, -8);
            //RTNA_DBG_Str(3, "\r\n");

            //UVCX_SetH264BitRate(0, (UVCX_BitRateLayers *)bitrate );
            // Do something here

#if (FPS_CTL == 1)   // bit rate control API test

            MMPS_3GPRECD_GetPreviewDisplay(&IsPreviewEnable);
            if(IsPreviewEnable){
                RTNA_DBG_Str(3, "br = ");
                MMPF_DBG_Int(gsUVCXBitRateLayers.dwAverageBitrate, -8);
                //RTNA_DBG_Str(3, ", fps= ");
                //MMPF_DBG_Int(MMPF_VIDENC_GetInputFPS(0), -2);
                //MMPF_DBG_Int(MMPF_VIDENC_GetOutputFPS(0), -2);
                RTNA_DBG_Str(3, "\r\n");

#if USING_UVCX_VIDEO_CONFIG==1
            UVCX_SetH264BitRate(0, &gsUVCXBitRateLayers);
#else
                glCustomTargetSizePerFrame = (gsUVCXBitRateLayers.dwAverageBitrate) / (8 * gsVideoEncodeFPS);

                if(MMP_ERR_NONE != MMPF_VIDENC_UpdateRateControl(0, gsUVCXBitRateLayers.dwAverageBitrate,
                                                                 MMPF_VIDENC_GetInputFPS(0),
                                                                 MMPF_VIDENC_GetOutputFPS(0))){
                    //error
                    RTNA_DBG_Str(3, "Error\r\n");
                }
#endif
            }
            else{
                RTNA_DBG_Str(3, "  ** gsSkypeBitRate = ");
                MMPF_DBG_Int(gsUVCXBitRateLayers.dwAverageBitrate, -8);
                RTNA_DBG_Str(3, "\r\n");

                //            gbVideoEncQualityCustom = MMP_TRUE;
                //            glCustomTargetSizePerFrame = (gsUVCXBitRateLayers.dwAverageBitrate)/(8 * gsVideoEncodeFPS);
                //            gbCustomQp = 45;
            }

#endif

            //uvcx_bitrate_layers_exit:

            USBInPhase = SET_CUR_CMD;
            usb_ep0_null_in();
            break;
        }
        /*
            case UVCX_QP_STEPS_LAYERS:                 // 3,3.15 UVCX_QP_STEPS_LAYERS
            {
                MMP_UBYTE qstep[UVCX_QPSTEP_SIZE_LEN] ;
                USBOutData = 0;
                USB_GET_FIFO_DATA(MMPF_USB_EP0,len,qstep, UVCX_QPSTEP_SIZE_LEN);
        //        UVCX_SetH264QPStepSize( (UVCX_QPStepSize *)qstep );
                // Do something here
                USBInPhase = SET_CUR_CMD;
                usb_ep0_null_in();
                break ;
            }
        */
        //case XU_CONTROL_UNDEFINED:
    default:
        // impossible flow
        break;
    }
}
#endif
